From b152d4f26980aecd447e6269e0e590d77b3d80cd Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 7 Dec 2018 20:03:46 +0100 Subject: [PATCH] fix(gatsby): fix false type conflict warning on plugin fields --- .../src/schema/__tests__/build-node-types-test.js | 10 ++++++++++ packages/gatsby/src/schema/build-node-types.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/src/schema/__tests__/build-node-types-test.js b/packages/gatsby/src/schema/__tests__/build-node-types-test.js index a30c752bba6a9..78a56861c5461 100644 --- a/packages/gatsby/src/schema/__tests__/build-node-types-test.js +++ b/packages/gatsby/src/schema/__tests__/build-node-types-test.js @@ -14,6 +14,9 @@ const createPageDependency = require(`../../redux/actions/add-page-dependency`) jest.mock(`../../redux/actions/add-page-dependency`) const nodeTypes = require(`../build-node-types`) +const { typeConflictReporter } = require(`../type-conflict-reporter`) +const addConflictSpy = jest.spyOn(typeConflictReporter, `addConflict`) + describe(`build-node-types`, () => { let schema, store, types @@ -26,6 +29,7 @@ describe(`build-node-types`, () => { beforeEach(async () => { createPageDependency.mockClear() + addConflictSpy.mockClear() const apiRunnerResponse = [ { pluginField: { @@ -58,6 +62,7 @@ describe(`build-node-types`, () => { hair: `brown`, children: [], parent: `p1`, + pluginField: `string`, }, { id: `c2`, @@ -65,6 +70,7 @@ describe(`build-node-types`, () => { hair: `blonde`, children: [], parent: `p1`, + pluginField: 5, }, ].forEach(n => store.dispatch({ type: `CREATE_NODE`, payload: n })) @@ -267,4 +273,8 @@ describe(`build-node-types`, () => { nodeId: `c2`, }) }) + + it(`should not report conflicts on plugin fields`, () => { + expect(typeConflictReporter.addConflict).not.toBeCalled() + }) }) diff --git a/packages/gatsby/src/schema/build-node-types.js b/packages/gatsby/src/schema/build-node-types.js index 3045878bf878d..04f55f7c267f7 100644 --- a/packages/gatsby/src/schema/build-node-types.js +++ b/packages/gatsby/src/schema/build-node-types.js @@ -20,7 +20,10 @@ const { nodeInterface } = require(`./node-interface`) const { getNodes, getNode } = require(`../db/nodes`) const pageDependencyResolver = require(`./page-dependency-resolver`) const { setFileNodeRootType } = require(`./types/type-file`) -const { clearTypeExampleValues } = require(`./data-tree-utils`) +const { + getExampleValues, + clearTypeExampleValues, +} = require(`./data-tree-utils`) const { run: runQuery } = require(`../db/nodes-query`) const lazyFields = require(`./lazy-fields`) @@ -200,9 +203,16 @@ async function buildProcessedType({ nodes, typeName, processedTypes, span }) { processedTypes, }) + const exampleValue = getExampleValues({ + nodes, + typeName, + ignoreFields: Object.keys(mergedFieldsFromPlugins), + }) + const nodeInputFields = inferInputObjectStructureFromNodes({ nodes, typeName, + exampleValue, }) const filterFields = _.merge(