Skip to content

Commit 7f10385

Browse files
GatsbyJS Botvladar
andauthored
fix(gatsby): improve deprecation text for missing childOf directive (#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]>
1 parent fd9d872 commit 7f10385

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

packages/gatsby/src/schema/extensions/__tests__/child-relations.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ describe(`Define parent-child relationships with field extensions`, () => {
174174
)
175175
await buildSchema()
176176
expect(report.warn).toBeCalledTimes(1)
177-
expect(report.warn).toBeCalledWith(
178-
`The type \`Parent\` does not explicitly define the field \`childChild\`.\n` +
179-
`On types with the \`@dontInfer\` directive, or with the \`infer\` ` +
180-
`extension set to \`false\`, automatically adding fields for ` +
181-
`children types is deprecated.\n` +
182-
`In Gatsby v3, only children fields explicitly set with the ` +
183-
`\`childOf\` extension will be added.\n`
177+
expect(report.warn.mock.calls[0][0]).toEqual(
178+
`Deprecation warning: In Gatsby v3 field \`Parent.childChild\` will not be added automatically ` +
179+
`because type \`Child\` does not explicitly list type \`Parent\` in \`childOf\` extension.\n` +
180+
`Add the following type definition to fix this:\n\n` +
181+
` type Child implements Node @childOf(types: ["Parent"]) {\n` +
182+
` id\n` +
183+
` }`
184184
)
185185
})
186186

packages/gatsby/src/schema/schema.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,15 @@ const addImplicitConvenienceChildrenFields = ({
10421042
const fieldName = many
10431043
? fieldNames.convenienceChildren(typeName)
10441044
: fieldNames.convenienceChild(typeName)
1045+
const manyArg = many ? `, many: true` : ``
10451046
report.warn(
1046-
`The type \`${parentTypeName}\` does not explicitly define ` +
1047-
`the field \`${fieldName}\`.\n` +
1048-
`On types with the \`@dontInfer\` directive, or with the \`infer\` ` +
1049-
`extension set to \`false\`, automatically adding fields for ` +
1050-
`children types is deprecated.\n` +
1051-
`In Gatsby v3, only children fields explicitly set with the ` +
1052-
`\`childOf\` extension will be added.\n`
1047+
`Deprecation warning: ` +
1048+
`In Gatsby v3 field \`${parentTypeName}.${fieldName}\` will not be added automatically because ` +
1049+
`type \`${typeName}\` does not explicitly list type \`${parentTypeName}\` in \`childOf\` extension.\n` +
1050+
`Add the following type definition to fix this:\n\n` +
1051+
` type ${typeName} implements Node @childOf(types: ["${parentTypeName}"]${manyArg}) {\n` +
1052+
` id\n` +
1053+
` }`
10531054
)
10541055
}
10551056
}

0 commit comments

Comments
 (0)