Skip to content

Commit

Permalink
fix(gatsby): improve deprecation text for missing childOf directive (#…
Browse files Browse the repository at this point in the history
…28532) (#28543)

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

* text formatting

* Add "many" argument

(cherry picked from commit f733f4e)

Co-authored-by: Vladimir Razuvaev <[email protected]>
  • Loading branch information
GatsbyJS Bot and vladar authored Dec 9, 2020
1 parent fd9d872 commit 7f10385
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
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

0 comments on commit 7f10385

Please sign in to comment.