Skip to content

Commit

Permalink
fix(gatsby): fix false type conflict warning on plugin fields (gatsby…
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored and gpetrioli committed Jan 22, 2019
1 parent 03ef4aa commit f41c7ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/gatsby/src/schema/__tests__/build-node-types-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,6 +29,7 @@ describe(`build-node-types`, () => {

beforeEach(async () => {
createPageDependency.mockClear()
addConflictSpy.mockClear()
const apiRunnerResponse = [
{
pluginField: {
Expand Down Expand Up @@ -58,13 +62,15 @@ describe(`build-node-types`, () => {
hair: `brown`,
children: [],
parent: `p1`,
pluginField: `string`,
},
{
id: `c2`,
internal: { type: `Child` },
hair: `blonde`,
children: [],
parent: `p1`,
pluginField: 5,
},
].forEach(n => store.dispatch({ type: `CREATE_NODE`, payload: n }))

Expand Down Expand Up @@ -267,4 +273,8 @@ describe(`build-node-types`, () => {
nodeId: `c2`,
})
})

it(`should not report conflicts on plugin fields`, () => {
expect(typeConflictReporter.addConflict).not.toBeCalled()
})
})
12 changes: 11 additions & 1 deletion packages/gatsby/src/schema/build-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f41c7ac

Please sign in to comment.