Skip to content

Commit fde5de6

Browse files
frodddwardpeet
authored andcommitted
fix(gatsby-source-contentful): Prevent TypeError if many-to-on… (#17500)
In the case of many-to-one references, the foreign reference is a string rather than an array. In this case, trying to create the reverse linkage results in a TypeError from attemtping to `push()` to a string. This checks the `push()` method can indeed be used to prevent such TypeError(s).
1 parent 4a34e3f commit fde5de6

File tree

3 files changed

+617
-3
lines changed

3 files changed

+617
-3
lines changed

packages/gatsby-source-contentful/src/__tests__/__snapshots__/normalize.js.snap

+293
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,153 @@ Our Lemnos products are made carefully by our craftsmen finely honed skillful te
19131913
},
19141914
},
19151915
],
1916+
Array [
1917+
Object {
1918+
"fields": Object {
1919+
"author": Object {
1920+
"en-US": Object {
1921+
"sys": Object {
1922+
"id": "qYfB1lzHTNpofY3Oqvjpk",
1923+
"linkType": "Entry",
1924+
"type": "Link",
1925+
},
1926+
},
1927+
},
1928+
"slug": Object {
1929+
"en-US": "post-one",
1930+
},
1931+
"title": Object {
1932+
"en-US": "Post one",
1933+
},
1934+
},
1935+
"sys": Object {
1936+
"contentType": Object {
1937+
"sys": Object {
1938+
"id": "blogPost",
1939+
"linkType": "ContentType",
1940+
"type": "Link",
1941+
},
1942+
},
1943+
"contentful_id": "5U1Lm7y197ZCNUI9USWPUV",
1944+
"createdAt": "2019-09-09T06:54:07.673Z",
1945+
"createdBy": Object {
1946+
"sys": Object {
1947+
"id": "2cRG5PXyp1roAoTOywZTW6",
1948+
"linkType": "User",
1949+
"type": "Link",
1950+
},
1951+
},
1952+
"environment": Object {
1953+
"sys": Object {
1954+
"id": "master",
1955+
"linkType": "Environment",
1956+
"type": "Link",
1957+
},
1958+
},
1959+
"firstPublishedAt": "2019-09-09T06:54:28.959Z",
1960+
"id": "c5U1Lm7y197ZCNUI9USWPUV",
1961+
"publishedAt": "2019-09-09T06:58:04.316Z",
1962+
"publishedBy": Object {
1963+
"sys": Object {
1964+
"id": "2cRG5PXyp1roAoTOywZTW6",
1965+
"linkType": "User",
1966+
"type": "Link",
1967+
},
1968+
},
1969+
"publishedCounter": 3,
1970+
"publishedVersion": 11,
1971+
"space": Object {
1972+
"sys": Object {
1973+
"id": "rocybtov1ozk",
1974+
"linkType": "Space",
1975+
"type": "Link",
1976+
},
1977+
},
1978+
"type": "Entry",
1979+
"updatedAt": "2019-09-09T06:58:04.316Z",
1980+
"updatedBy": Object {
1981+
"sys": Object {
1982+
"id": "2cRG5PXyp1roAoTOywZTW6",
1983+
"linkType": "User",
1984+
"type": "Link",
1985+
},
1986+
},
1987+
"version": 12,
1988+
},
1989+
},
1990+
],
1991+
Array [
1992+
Object {
1993+
"fields": Object {
1994+
"favouritePost": Object {
1995+
"en-US": Object {
1996+
"sys": Object {
1997+
"id": "c5U1Lm7y197ZCNUI9USWPUV",
1998+
"linkType": "Entry",
1999+
"type": "Link",
2000+
},
2001+
},
2002+
},
2003+
"name": Object {
2004+
"en-US": "Fred",
2005+
},
2006+
},
2007+
"sys": Object {
2008+
"contentType": Object {
2009+
"sys": Object {
2010+
"id": "author",
2011+
"linkType": "ContentType",
2012+
"type": "Link",
2013+
},
2014+
},
2015+
"contentful_id": "qYfB1lzHTNpofY3Oqvjpk",
2016+
"createdAt": "2019-09-09T06:54:16.287Z",
2017+
"createdBy": Object {
2018+
"sys": Object {
2019+
"id": "2cRG5PXyp1roAoTOywZTW6",
2020+
"linkType": "User",
2021+
"type": "Link",
2022+
},
2023+
},
2024+
"environment": Object {
2025+
"sys": Object {
2026+
"id": "master",
2027+
"linkType": "Environment",
2028+
"type": "Link",
2029+
},
2030+
},
2031+
"firstPublishedAt": "2019-09-09T06:54:22.644Z",
2032+
"id": "qYfB1lzHTNpofY3Oqvjpk",
2033+
"publishedAt": "2019-09-09T06:54:38.816Z",
2034+
"publishedBy": Object {
2035+
"sys": Object {
2036+
"id": "2cRG5PXyp1roAoTOywZTW6",
2037+
"linkType": "User",
2038+
"type": "Link",
2039+
},
2040+
},
2041+
"publishedCounter": 2,
2042+
"publishedVersion": 6,
2043+
"space": Object {
2044+
"sys": Object {
2045+
"id": "rocybtov1ozk",
2046+
"linkType": "Space",
2047+
"type": "Link",
2048+
},
2049+
},
2050+
"type": "Entry",
2051+
"updatedAt": "2019-09-09T06:54:38.816Z",
2052+
"updatedBy": Object {
2053+
"sys": Object {
2054+
"id": "2cRG5PXyp1roAoTOywZTW6",
2055+
"linkType": "User",
2056+
"type": "Link",
2057+
},
2058+
},
2059+
"version": 7,
2060+
},
2061+
},
2062+
],
19162063
]
19172064
`;
19182065
@@ -1972,6 +2119,12 @@ Object {
19722119
"name": "brand___NODE",
19732120
},
19742121
],
2122+
"c5U1Lm7y197ZCNUI9USWPUV": Array [
2123+
Object {
2124+
"id": "qYfB1lzHTNpofY3Oqvjpk",
2125+
"name": "author___NODE",
2126+
},
2127+
],
19752128
"c651CQ8rLoIYCeY6G0QG22q": Array [
19762129
Object {
19772130
"id": "c3DVqIYj4dOwwcKu6sgqOgg",
@@ -2008,6 +2161,12 @@ Object {
20082161
"name": "product___NODE",
20092162
},
20102163
],
2164+
"qYfB1lzHTNpofY3Oqvjpk": Array [
2165+
Object {
2166+
"id": "c5U1Lm7y197ZCNUI9USWPUV",
2167+
"name": "blog post___NODE",
2168+
},
2169+
],
20112170
"wtrHxeu3zEoEce2MokCSi": Array [
20122171
Object {
20132172
"id": "c5KsDBWseXY6QegucYAoacS",
@@ -2030,6 +2189,8 @@ Set {
20302189
"c4BqrajvA8E6qwgkieoqmqO",
20312190
"c71mfnH4QKsSsQmgoaQuq6O",
20322191
"c4L2GhTsJtCseMYM8Wia64i",
2192+
"c5U1Lm7y197ZCNUI9USWPUV",
2193+
"qYfB1lzHTNpofY3Oqvjpk",
20332194
"c3wtvPBbBjiMKqKKga8I2Cu",
20342195
"KTRF62Q4gg60q6WCsWKw8",
20352196
"Xc0ny7GWsMEMCeASWO2um",
@@ -4297,5 +4458,137 @@ Unsere Lemnos Produkte werden sorgfältig von unseren Handwerkern fein geschliff
42974458
"parent": "uuid-from-gatsby",
42984459
},
42994460
],
4461+
Array [
4462+
Object {
4463+
"children": Array [],
4464+
"description": "",
4465+
"displayField": "title",
4466+
"id": "uuid-from-gatsby",
4467+
"internal": Object {
4468+
"contentDigest": "6ea09658e67ecfc838a195ab96bd8ef9",
4469+
"type": "ContentfulContentType",
4470+
},
4471+
"name": "Blog Post",
4472+
"parent": null,
4473+
},
4474+
],
4475+
Array [
4476+
Object {
4477+
"author___NODE": "uuid-from-gatsby",
4478+
"children": Array [],
4479+
"contentful_id": "c5U1Lm7y197ZCNUI9USWPUV",
4480+
"createdAt": "2019-09-09T06:54:07.673Z",
4481+
"id": "uuid-from-gatsby",
4482+
"internal": Object {
4483+
"contentDigest": "972a70e0665af76f7bc8e053fa803826",
4484+
"type": "ContentfulBlogPost",
4485+
},
4486+
"node_locale": "en-US",
4487+
"parent": "Blog Post",
4488+
"slug": "post-one",
4489+
"title": "Post one",
4490+
"updatedAt": "2019-09-09T06:58:04.316Z",
4491+
},
4492+
],
4493+
Array [
4494+
Object {
4495+
"children": Array [],
4496+
"description": "",
4497+
"displayField": "title",
4498+
"id": "uuid-from-gatsby",
4499+
"internal": Object {
4500+
"contentDigest": "6ea09658e67ecfc838a195ab96bd8ef9",
4501+
"type": "ContentfulContentType",
4502+
},
4503+
"name": "Blog Post",
4504+
"parent": null,
4505+
},
4506+
],
4507+
Array [
4508+
Object {
4509+
"author___NODE": "uuid-from-gatsby",
4510+
"children": Array [],
4511+
"contentful_id": "c5U1Lm7y197ZCNUI9USWPUV",
4512+
"createdAt": "2019-09-09T06:54:07.673Z",
4513+
"id": "uuid-from-gatsby",
4514+
"internal": Object {
4515+
"contentDigest": "63156d744a2ae97f222299a400750d46",
4516+
"type": "ContentfulBlogPost",
4517+
},
4518+
"node_locale": "de",
4519+
"parent": "Blog Post",
4520+
"slug": "post-one",
4521+
"title": "Post one",
4522+
"updatedAt": "2019-09-09T06:58:04.316Z",
4523+
},
4524+
],
4525+
Array [
4526+
Object {
4527+
"children": Array [],
4528+
"description": "",
4529+
"displayField": "name",
4530+
"id": "uuid-from-gatsby",
4531+
"internal": Object {
4532+
"contentDigest": "feb97892424b0df5c4d78a7a36e6bb6c",
4533+
"type": "ContentfulContentType",
4534+
},
4535+
"name": "Author",
4536+
"parent": null,
4537+
},
4538+
],
4539+
Array [
4540+
Object {
4541+
"blog post___NODE": Array [
4542+
"uuid-from-gatsby",
4543+
],
4544+
"children": Array [],
4545+
"contentful_id": "qYfB1lzHTNpofY3Oqvjpk",
4546+
"createdAt": "2019-09-09T06:54:16.287Z",
4547+
"favouritePost___NODE": "uuid-from-gatsby",
4548+
"id": "uuid-from-gatsby",
4549+
"internal": Object {
4550+
"contentDigest": "55478da16d88e82dd0a94180aa966976",
4551+
"type": "ContentfulAuthor",
4552+
},
4553+
"name": "Fred",
4554+
"node_locale": "en-US",
4555+
"parent": "Author",
4556+
"updatedAt": "2019-09-09T06:54:38.816Z",
4557+
},
4558+
],
4559+
Array [
4560+
Object {
4561+
"children": Array [],
4562+
"description": "",
4563+
"displayField": "name",
4564+
"id": "uuid-from-gatsby",
4565+
"internal": Object {
4566+
"contentDigest": "feb97892424b0df5c4d78a7a36e6bb6c",
4567+
"type": "ContentfulContentType",
4568+
},
4569+
"name": "Author",
4570+
"parent": null,
4571+
},
4572+
],
4573+
Array [
4574+
Object {
4575+
"blog post___NODE": Array [
4576+
"uuid-from-gatsby",
4577+
],
4578+
"children": Array [],
4579+
"contentful_id": "qYfB1lzHTNpofY3Oqvjpk",
4580+
"createdAt": "2019-09-09T06:54:16.287Z",
4581+
"favouritePost___NODE": "uuid-from-gatsby",
4582+
"id": "uuid-from-gatsby",
4583+
"internal": Object {
4584+
"contentDigest": "60afe7cfb871c52d3e1c8b856f00be5b",
4585+
"type": "ContentfulAuthor",
4586+
},
4587+
"name": "Fred",
4588+
"node_locale": "de",
4589+
"parent": "Author",
4590+
"updatedAt": "2019-09-09T06:54:38.816Z",
4591+
},
4592+
],
43004593
]
43014594
`;

0 commit comments

Comments
 (0)