Skip to content

Commit 6b7ed63

Browse files
authoredMar 2, 2020
feat(gatsby): Allow silencing the warning for adding resolvers for missing types (#21769)
* feat: Allow silencing the warning for adding resolvers to nonexistent types * add period
1 parent b577e51 commit 6b7ed63

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎packages/gatsby/src/schema/schema.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ const processThirdPartyTypeFields = ({ typeComposer, schemaQueryType }) => {
746746

747747
const addCustomResolveFunctions = async ({ schemaComposer, parentSpan }) => {
748748
const intermediateSchema = schemaComposer.buildSchema()
749-
const createResolvers = resolvers => {
749+
const createResolvers = (
750+
resolvers,
751+
{ ignoreNonexistentTypes = false } = {}
752+
) => {
750753
Object.keys(resolvers).forEach(typeName => {
751754
const fields = resolvers[typeName]
752755
if (schemaComposer.has(typeName)) {
@@ -814,7 +817,7 @@ const addCustomResolveFunctions = async ({ schemaComposer, parentSpan }) => {
814817
tc.setFieldExtension(fieldName, `createdFrom`, `createResolvers`)
815818
}
816819
})
817-
} else {
820+
} else if (!ignoreNonexistentTypes) {
818821
report.warn(
819822
`\`createResolvers\` passed resolvers for type \`${typeName}\` that ` +
820823
`doesn't exist in the schema. Use \`createTypes\` to add the type ` +

‎packages/gatsby/src/utils/api-node-docs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ exports.createSchemaCustomization = true
287287
* @param {GraphQLSchema} $0.intermediateSchema Current GraphQL schema
288288
* @param {function} $0.createResolvers Add custom resolvers to GraphQL field configs
289289
* @param {object} $1
290-
* @param {object} $1.resolvers Resolvers from plugin options in `gatsby-config.js`.
290+
* @param {object} $1.resolvers An object map of GraphQL type names to custom resolver functions.
291+
* @param {object} $1.options Optional createResolvers options.
292+
* @param {object} $1.options.ignoreNonexistentTypes Silences the warning when trying to add resolvers for types that don't exist. Useful for optional extensions.
291293
* @example
292294
* exports.createResolvers = ({ createResolvers }) => {
293295
* const resolvers = {

0 commit comments

Comments
 (0)
Please sign in to comment.