Skip to content

Commit 8986b12

Browse files
GatsbyJS BotTylerBarnes
andauthored
fix(gatsby-source-wordpress): auto-rename types named "Filter" (#29718) (#29884)
Co-authored-by: gatsbybot <[email protected]> (cherry picked from commit fb225be) Co-authored-by: Tyler Barnes <[email protected]>
1 parent c2ea9b9 commit 8986b12

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

packages/gatsby-source-wordpress/src/steps/create-schema-customization/build-types.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "./helpers"
1010

1111
const unionType = typeBuilderApi => {
12-
const { typeDefs, schema, type, pluginOptions } = typeBuilderApi
12+
const { schema, type, pluginOptions } = typeBuilderApi
1313

1414
const types = type.possibleTypes
1515
.filter(
@@ -22,7 +22,7 @@ const unionType = typeBuilderApi => {
2222
.map(possibleType => buildTypeName(possibleType.name))
2323

2424
if (!types || !types.length) {
25-
return
25+
return false
2626
}
2727

2828
let unionType = {
@@ -47,13 +47,12 @@ const unionType = typeBuilderApi => {
4747
// @todo add this as a plugin option
4848
unionType = filterTypeDefinition(unionType, typeBuilderApi, `UNION`)
4949

50-
typeDefs.push(schema.buildUnionType(unionType))
50+
return schema.buildUnionType(unionType)
5151
}
5252

5353
const interfaceType = typeBuilderApi => {
5454
const {
5555
type,
56-
typeDefs,
5756
schema,
5857
gatsbyNodeTypes,
5958
fieldAliases,
@@ -111,7 +110,7 @@ const interfaceType = typeBuilderApi => {
111110
// @todo add this as a plugin option
112111
typeDef = filterTypeDefinition(typeDef, typeBuilderApi, `INTERFACE`)
113112

114-
typeDefs.push(schema.buildInterfaceType(typeDef))
113+
return schema.buildInterfaceType(typeDef)
115114
}
116115

117116
const objectType = typeBuilderApi => {
@@ -120,7 +119,6 @@ const objectType = typeBuilderApi => {
120119
gatsbyNodeTypes,
121120
fieldAliases,
122121
fieldBlacklist,
123-
typeDefs,
124122
schema,
125123
isAGatsbyNode,
126124
} = typeBuilderApi
@@ -138,7 +136,7 @@ const objectType = typeBuilderApi => {
138136
// TypeError: Cannot convert undefined or null to object at Function.keys (<anonymous>)
139137
// Also cause wordpress blog site build failure in createSchemaCustomization step
140138
if (!transformedFields || !Object.keys(transformedFields).length) {
141-
return
139+
return false
142140
}
143141

144142
let objectType = {
@@ -180,21 +178,18 @@ const objectType = typeBuilderApi => {
180178
// @todo add this as a plugin option
181179
objectType = filterTypeDefinition(objectType, typeBuilderApi, `OBJECT`)
182180

183-
typeDefs.push(schema.buildObjectType(objectType))
181+
return schema.buildObjectType(objectType)
184182
}
185183

186-
const enumType = ({ typeDefs, schema, type }) => {
187-
typeDefs.push(
188-
schema.buildEnumType({
189-
name: buildTypeName(type.name),
190-
values: type.enumValues.reduce((accumulator, { name }) => {
191-
accumulator[name] = { name }
192-
193-
return accumulator
194-
}, {}),
195-
description: type.description,
196-
})
197-
)
198-
}
184+
const enumType = ({ schema, type }) =>
185+
schema.buildEnumType({
186+
name: buildTypeName(type.name),
187+
values: type.enumValues.reduce((accumulator, { name }) => {
188+
accumulator[name] = { name }
189+
190+
return accumulator
191+
}, {}),
192+
description: type.description,
193+
})
199194

200195
export default { unionType, interfaceType, objectType, enumType }

packages/gatsby-source-wordpress/src/steps/create-schema-customization/helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export const buildTypeName = name => {
2020
return name
2121
}
2222

23+
if (name === `Filter`) {
24+
name = `FilterType`
25+
}
26+
2327
return prefix + name
2428
}
2529

packages/gatsby-source-wordpress/src/steps/create-schema-customization/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ const customizeSchema = async ({ actions, schema }) => {
4242
fieldOfTypeWasFetched(type) &&
4343
!typeIsExcluded({ pluginOptions, typeName: type.name })
4444
) {
45+
let builtType
46+
4547
switch (type.kind) {
4648
case `UNION`:
47-
buildType.unionType({ ...typeBuilderApi, type })
49+
builtType = buildType.unionType({ ...typeBuilderApi, type })
4850
break
4951
case `INTERFACE`:
50-
buildType.interfaceType({ ...typeBuilderApi, type })
52+
builtType = buildType.interfaceType({ ...typeBuilderApi, type })
5153
break
5254
case `OBJECT`:
53-
buildType.objectType({ ...typeBuilderApi, type })
55+
builtType = buildType.objectType({ ...typeBuilderApi, type })
5456
break
5557
case `ENUM`:
56-
buildType.enumType({ ...typeBuilderApi, type })
58+
builtType = buildType.enumType({ ...typeBuilderApi, type })
5759
break
5860
case `SCALAR`:
5961
/**
@@ -62,14 +64,18 @@ const customizeSchema = async ({ actions, schema }) => {
6264
*/
6365
break
6466
}
67+
68+
if (builtType) {
69+
typeDefs.push(builtType)
70+
}
6571
}
6672
})
6773

6874
// Create non Gatsby node types by creating a single node
6975
// where the typename is the type prefix
7076
// The node fields are the non-node root fields of the remote schema
7177
// like so: query { prefix { ...fields } }
72-
buildType.objectType({
78+
const wpType = buildType.objectType({
7379
...typeBuilderApi,
7480
type: {
7581
kind: `OBJECT`,
@@ -81,6 +87,8 @@ const customizeSchema = async ({ actions, schema }) => {
8187
isAGatsbyNode: true,
8288
})
8389

90+
typeDefs.push(wpType)
91+
8492
actions.createTypes(typeDefs)
8593
}
8694

0 commit comments

Comments
 (0)