Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): improve deprecation text for missing childOf directive #28532

Merged
merged 3 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ describe(`Define parent-child relationships with field extensions`, () => {
)
await buildSchema()
expect(report.warn).toBeCalledTimes(1)
expect(report.warn).toBeCalledWith(
`The type \`Parent\` does not explicitly define the field \`childChild\`.\n` +
`On types with the \`@dontInfer\` directive, or with the \`infer\` ` +
`extension set to \`false\`, automatically adding fields for ` +
`children types is deprecated.\n` +
`In Gatsby v3, only children fields explicitly set with the ` +
`\`childOf\` extension will be added.\n`
expect(report.warn.mock.calls[0][0]).toEqual(
`Deprecation warning: In Gatsby v3 field \`Parent.childChild\` will not be added automatically ` +
`because type \`Child\` does not explicitly list type \`Parent\` in \`childOf\` extension.\n` +
`Add the following type definition to fix this:\n\n` +
` type Child implements Node @childOf(types: ["Parent"]) {\n` +
` id\n` +
` }`
)
})

Expand Down
15 changes: 8 additions & 7 deletions packages/gatsby/src/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,15 @@ const addImplicitConvenienceChildrenFields = ({
const fieldName = many
? fieldNames.convenienceChildren(typeName)
: fieldNames.convenienceChild(typeName)
const manyArg = many ? `, many: true` : ``
report.warn(
`The type \`${parentTypeName}\` does not explicitly define ` +
`the field \`${fieldName}\`.\n` +
`On types with the \`@dontInfer\` directive, or with the \`infer\` ` +
`extension set to \`false\`, automatically adding fields for ` +
`children types is deprecated.\n` +
`In Gatsby v3, only children fields explicitly set with the ` +
`\`childOf\` extension will be added.\n`
`Deprecation warning: ` +
`In Gatsby v3 field \`${parentTypeName}.${fieldName}\` will not be added automatically because ` +
`type \`${typeName}\` does not explicitly list type \`${parentTypeName}\` in \`childOf\` extension.\n` +
`Add the following type definition to fix this:\n\n` +
` type ${typeName} implements Node @childOf(types: ["${parentTypeName}"]${manyArg}) {\n` +
` id\n` +
` }`
)
}
}
Expand Down