Skip to content

Commit dd52a14

Browse files
authored
fix(gatsby-source-wordpress): WPGraphQL 1.13.0 compatibility (#37134)
1 parent 1c84345 commit dd52a14

File tree

22 files changed

+424
-250
lines changed

22 files changed

+424
-250
lines changed

integration-tests/gatsby-source-wordpress/__tests__/__snapshots__/index.js.snap

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Object {
9595
"databaseId": 564,
9696
"id": "cG9zdDo1NjQ=",
9797
"label": "Activity",
98-
"nodeType": "MenuItem",
9998
"target": null,
10099
"title": null,
101100
"url": "/activity/",
@@ -132,7 +131,6 @@ Object {
132131
"databaseId": 565,
133132
"id": "cG9zdDo1NjU=",
134133
"label": "Sample Page",
135-
"nodeType": "MenuItem",
136134
"target": null,
137135
"title": null,
138136
"url": "/sample-page/",
@@ -154,7 +152,6 @@ Object {
154152
"databaseId": 566,
155153
"id": "cG9zdDo1NjY=",
156154
"label": "Hello world!",
157-
"nodeType": "MenuItem",
158155
"target": null,
159156
"title": null,
160157
"url": "/2020/02/25/hello-world/",
@@ -166,7 +163,6 @@ Object {
166163
"databaseId": 567,
167164
"id": "cG9zdDo1Njc=",
168165
"label": "test custom link",
169-
"nodeType": "MenuItem",
170166
"target": null,
171167
"title": null,
172168
"url": "https://google.com",
@@ -218,7 +214,6 @@ Object {
218214
"databaseId": 564,
219215
"id": "cG9zdDo1NjQ=",
220216
"label": "Activity",
221-
"nodeType": "MenuItem",
222217
"target": null,
223218
"title": null,
224219
"url": "/activity/",
@@ -255,7 +250,6 @@ Object {
255250
"databaseId": 565,
256251
"id": "cG9zdDo1NjU=",
257252
"label": "Sample Page",
258-
"nodeType": "MenuItem",
259253
"target": null,
260254
"title": null,
261255
"url": "/sample-page/",
@@ -277,7 +271,6 @@ Object {
277271
"databaseId": 566,
278272
"id": "cG9zdDo1NjY=",
279273
"label": "Hello world!",
280-
"nodeType": "MenuItem",
281274
"target": null,
282275
"title": null,
283276
"url": "/2020/02/25/hello-world/",
@@ -289,7 +282,6 @@ Object {
289282
"databaseId": 567,
290283
"id": "cG9zdDo1Njc=",
291284
"label": "test custom link",
292-
"nodeType": "MenuItem",
293285
"target": null,
294286
"title": null,
295287
"url": "https://google.com",
@@ -783,7 +775,6 @@ Object {
783775
"writingSettingsDefaultPostFormat": "",
784776
"writingSettingsUseSmilies": true,
785777
},
786-
"nodeType": null,
787778
"writingSettings": Object {
788779
"defaultCategory": 23,
789780
"defaultPostFormat": "0",
@@ -960,7 +951,6 @@ Array [
960951
"seo",
961952
"viewer",
962953
"writingSettings",
963-
"nodeType",
964954
"id",
965955
"parent",
966956
"children",
@@ -1106,7 +1096,6 @@ Array [
11061096
"termGroupId",
11071097
"termTaxonomyId",
11081098
"uri",
1109-
"nodeType",
11101099
"parent",
11111100
"children",
11121101
"internal",
@@ -1292,7 +1281,6 @@ Array [
12921281
"parentId",
12931282
"replies",
12941283
"type",
1295-
"nodeType",
12961284
"parent",
12971285
"children",
12981286
"internal",
@@ -1307,7 +1295,6 @@ Array [
13071295
"id",
13081296
"name",
13091297
"url",
1310-
"nodeType",
13111298
"parent",
13121299
"children",
13131300
"internal",
@@ -1544,7 +1531,6 @@ Array [
15441531
"slug",
15451532
"status",
15461533
"uri",
1547-
"nodeType",
15481534
"parent",
15491535
"children",
15501536
"internal",
@@ -1700,7 +1686,6 @@ Array [
17001686
"showInRest",
17011687
"showUi",
17021688
"uri",
1703-
"nodeType",
17041689
"parent",
17051690
"children",
17061691
"internal",
@@ -5783,7 +5768,6 @@ Array [
57835768
"status",
57845769
"title",
57855770
"uri",
5786-
"nodeType",
57875771
"localFile",
57885772
"parent",
57895773
"children",
@@ -5936,7 +5920,6 @@ Array [
59365920
"menuItems",
59375921
"name",
59385922
"slug",
5939-
"nodeType",
59405923
"parent",
59415924
"children",
59425925
"internal",
@@ -6008,7 +5991,6 @@ Array [
60085991
"target",
60095992
"title",
60105993
"url",
6011-
"nodeType",
60125994
"parent",
60135995
"children",
60145996
"internal",
@@ -6259,9 +6241,62 @@ Array [
62596241
"status",
62606242
"template",
62616243
"uri",
6244+
"parent",
6245+
"children",
6246+
"internal",
62626247
],
62636248
"name": "WpNodeWithFeaturedImage",
62646249
},
6250+
Object {
6251+
"fields": Array [
6252+
"totalCount",
6253+
"edges",
6254+
"nodes",
6255+
"pageInfo",
6256+
"distinct",
6257+
"max",
6258+
"min",
6259+
"sum",
6260+
"group",
6261+
],
6262+
"name": "WpNodeWithFeaturedImageConnection",
6263+
},
6264+
Object {
6265+
"fields": Array [
6266+
"next",
6267+
"node",
6268+
"previous",
6269+
],
6270+
"name": "WpNodeWithFeaturedImageEdge",
6271+
},
6272+
Object {
6273+
"fields": null,
6274+
"name": "WpNodeWithFeaturedImageFieldSelector",
6275+
},
6276+
Object {
6277+
"fields": null,
6278+
"name": "WpNodeWithFeaturedImageFilterInput",
6279+
},
6280+
Object {
6281+
"fields": Array [
6282+
"totalCount",
6283+
"edges",
6284+
"nodes",
6285+
"pageInfo",
6286+
"distinct",
6287+
"max",
6288+
"min",
6289+
"sum",
6290+
"group",
6291+
"field",
6292+
"fieldValue",
6293+
],
6294+
"name": "WpNodeWithFeaturedImageGroupConnection",
6295+
},
6296+
Object {
6297+
"fields": null,
6298+
"name": "WpNodeWithFeaturedImageSortInput",
6299+
},
62656300
Object {
62666301
"fields": Array [
62676302
"node",
@@ -6359,7 +6394,6 @@ Array [
63596394
"template",
63606395
"title",
63616396
"uri",
6362-
"nodeType",
63636397
"beforeChangeNodeTest",
63646398
"parent",
63656399
"children",
@@ -6616,7 +6650,6 @@ Array [
66166650
"title",
66176651
"toPing",
66186652
"uri",
6619-
"nodeType",
66206653
"beforeChangeNodeTest",
66216654
"parent",
66226655
"children",
@@ -6677,7 +6710,6 @@ Array [
66776710
"termGroupId",
66786711
"termTaxonomyId",
66796712
"uri",
6680-
"nodeType",
66816713
"parent",
66826714
"children",
66836715
"internal",
@@ -7036,7 +7068,6 @@ Array [
70367068
"template",
70377069
"title",
70387070
"uri",
7039-
"nodeType",
70407071
"parent",
70417072
"children",
70427073
"internal",
@@ -7722,7 +7753,6 @@ Array [
77227753
"termGroupId",
77237754
"termTaxonomyId",
77247755
"uri",
7725-
"nodeType",
77267756
"parent",
77277757
"children",
77287758
"internal",
@@ -7859,7 +7889,6 @@ Array [
78597889
"showInQuickEdit",
78607890
"showInRest",
78617891
"showUi",
7862-
"nodeType",
78637892
"parent",
78647893
"children",
78657894
"internal",
@@ -7994,7 +8023,6 @@ Array [
79948023
"termGroupId",
79958024
"termTaxonomyId",
79968025
"uri",
7997-
"nodeType",
79988026
"parent",
79998027
"children",
80008028
"internal",
@@ -8089,7 +8117,6 @@ Array [
80898117
"template",
80908118
"title",
80918119
"uri",
8092-
"nodeType",
80938120
"parent",
80948121
"children",
80958122
"internal",
@@ -8184,7 +8211,6 @@ Array [
81848211
"template",
81858212
"title",
81868213
"uri",
8187-
"nodeType",
81888214
"parent",
81898215
"children",
81908216
"internal",
@@ -8279,7 +8305,6 @@ Array [
82798305
"template",
82808306
"title",
82818307
"uri",
8282-
"nodeType",
82838308
"parent",
82848309
"children",
82858310
"internal",
@@ -8376,7 +8401,6 @@ Array [
83768401
"uri",
83778402
"url",
83788403
"username",
8379-
"nodeType",
83808404
"parent",
83818405
"children",
83828406
"internal",
@@ -8435,7 +8459,6 @@ Array [
84358459
"displayName",
84368460
"id",
84378461
"name",
8438-
"nodeType",
84398462
"parent",
84408463
"children",
84418464
"internal",

integration-tests/gatsby-source-wordpress/__tests__/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,45 @@ const {
1818
resetSchema,
1919
} = require(`../test-fns/test-utils/increment-remote-data`)
2020

21+
const {
22+
default: fetchGraphql,
23+
} = require("gatsby-source-wordpress/dist/utils/fetch-graphql")
24+
2125
jest.setTimeout(100000)
2226

27+
const pluginsAreReady = async () => {
28+
let pluginsAreReady = false
29+
let tryCount = 0
30+
31+
while (!pluginsAreReady && tryCount < 20) {
32+
try {
33+
tryCount++
34+
35+
const response = await fetchGraphql({
36+
url: `http://localhost:8001/graphql`,
37+
query: /* GraphQL */ `
38+
{
39+
__type(name: "AttachFeaturedImageToNodeByIdPayload") {
40+
name
41+
}
42+
}
43+
`,
44+
})
45+
46+
if (
47+
response?.data?.__type?.name === `AttachFeaturedImageToNodeByIdPayload`
48+
) {
49+
pluginsAreReady = true
50+
}
51+
} catch (e) {
52+
console.error(e)
53+
await new Promise(resolve => setTimeout(resolve, 1000))
54+
}
55+
}
56+
57+
return pluginsAreReady
58+
}
59+
2360
// we run these tests twice in a row
2461
// to make sure everything passes on a warm cache build
2562
// we don't need to re-run some tests the second time,
@@ -34,6 +71,9 @@ describe(`[gatsby-source-wordpress] Build default options`, () => {
3471
console.log(`Waiting for WPGraphQL to be ready...`)
3572
await urling({ url: `http://localhost:8001/graphql`, retry: 100 })
3673
console.log(`WPGraphQL is ready`)
74+
console.log(`Waiting for plugins to be ready...`)
75+
await pluginsAreReady()
76+
console.log(`Plugins are ready`)
3777

3878
if (isWarmCache) {
3979
done()

integration-tests/gatsby-source-wordpress/test-fns/test-utils/queries.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ exports.queries = {
530530
id
531531
label
532532
databaseId
533-
nodeType
534533
target
535534
title
536535
url
@@ -670,7 +669,6 @@ exports.queries = {
670669
writingSettingsDefaultPostFormat
671670
writingSettingsUseSmilies
672671
}
673-
nodeType
674672
writingSettings {
675673
defaultCategory
676674
defaultPostFormat

packages/gatsby-source-wordpress/src/models/remoteSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { findTypeName } from "~/steps/create-schema-customization/helpers"
2+
import { findNamedTypeName } from "~/steps/create-schema-customization/helpers"
33

44
interface IRemoteSchemaState {
55
wpUrl: string
@@ -130,7 +130,7 @@ const remoteSchema: IRemoteSchemaStore = {
130130
},
131131

132132
addFetchedType(state, type) {
133-
const key = findTypeName(type)
133+
const key = findNamedTypeName(type)
134134

135135
if (!key) {
136136
return state

0 commit comments

Comments
 (0)