diff --git a/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js b/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js index d032dfa071374..9d235e97e526d 100644 --- a/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js +++ b/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js @@ -171,6 +171,24 @@ describe(`build and update schema for SitePage`, () => { await testNestedFields() }) + it(`updates nested input types on rebuild`, async () => { + // sanity-check + const inputFields = Object.keys( + schema.getType(`SitePageFieldsFilterInput`).getFields() + ) + expect(inputFields.length).toBe(1) + expect(inputFields).toEqual([`oldKey`]) + + // Rebuild + const page = firstPage() + page.fields = {} + store.dispatch({ type: `CREATE_NODE`, payload: page }) + await rebuildWithSitePage({}) + schema = store.getState().schema + + expect(schema.getType(`SitePageFieldsFilterInput`)).toBeUndefined() + }) + it(`respects @dontInfer on SitePage`, async () => { const typeDefs = ` type SitePage implements Node @dontInfer { diff --git a/packages/gatsby/src/schema/types/derived-types.ts b/packages/gatsby/src/schema/types/derived-types.ts index 12cb95c1a0f73..8f52f3e82a4c1 100644 --- a/packages/gatsby/src/schema/types/derived-types.ts +++ b/packages/gatsby/src/schema/types/derived-types.ts @@ -65,6 +65,15 @@ export const deleteFieldsOfDerivedTypes = ({ typeComposer }): void => { }) } +const removeTypeFromSchemaComposer = ({ + schemaComposer, + typeComposer, +}): void => { + schemaComposer.delete(typeComposer.getTypeName()) + schemaComposer.delete((typeComposer as any)._gqType) + schemaComposer.delete(typeComposer) +} + export const clearDerivedTypes = ({ schemaComposer, typeComposer, @@ -77,15 +86,21 @@ export const clearDerivedTypes = ({ for (const typeName of derivedTypes.values()) { const derivedTypeComposer = schemaComposer.getAnyTC(typeName) clearDerivedTypes({ schemaComposer, typeComposer: derivedTypeComposer }) - schemaComposer.delete(typeName) - schemaComposer.delete((derivedTypeComposer as any)._gqType) - schemaComposer.delete(derivedTypeComposer) + removeTypeFromSchemaComposer({ + schemaComposer, + typeComposer: derivedTypeComposer, + }) } if ( typeComposer instanceof ObjectTypeComposer || typeComposer instanceof InterfaceTypeComposer ) { + const inputTypeComposer = typeComposer.getInputTypeComposer() + removeTypeFromSchemaComposer({ + schemaComposer, + typeComposer: inputTypeComposer, + }) typeComposer.removeInputTypeComposer() }