Skip to content

Commit

Permalink
feat(gatsby): Allow silencing the warning for adding resolvers for mi…
Browse files Browse the repository at this point in the history
…ssing types (#21769)

* feat: Allow silencing the warning for adding resolvers to nonexistent types

* add period
  • Loading branch information
jquense committed Mar 2, 2020
1 parent b577e51 commit 6b7ed63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/gatsby/src/schema/schema.js
Expand Up @@ -746,7 +746,10 @@ const processThirdPartyTypeFields = ({ typeComposer, schemaQueryType }) => {

const addCustomResolveFunctions = async ({ schemaComposer, parentSpan }) => {
const intermediateSchema = schemaComposer.buildSchema()
const createResolvers = resolvers => {
const createResolvers = (
resolvers,
{ ignoreNonexistentTypes = false } = {}
) => {
Object.keys(resolvers).forEach(typeName => {
const fields = resolvers[typeName]
if (schemaComposer.has(typeName)) {
Expand Down Expand Up @@ -814,7 +817,7 @@ const addCustomResolveFunctions = async ({ schemaComposer, parentSpan }) => {
tc.setFieldExtension(fieldName, `createdFrom`, `createResolvers`)
}
})
} else {
} else if (!ignoreNonexistentTypes) {
report.warn(
`\`createResolvers\` passed resolvers for type \`${typeName}\` that ` +
`doesn't exist in the schema. Use \`createTypes\` to add the type ` +
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/src/utils/api-node-docs.js
Expand Up @@ -287,7 +287,9 @@ exports.createSchemaCustomization = true
* @param {GraphQLSchema} $0.intermediateSchema Current GraphQL schema
* @param {function} $0.createResolvers Add custom resolvers to GraphQL field configs
* @param {object} $1
* @param {object} $1.resolvers Resolvers from plugin options in `gatsby-config.js`.
* @param {object} $1.resolvers An object map of GraphQL type names to custom resolver functions.
* @param {object} $1.options Optional createResolvers options.
* @param {object} $1.options.ignoreNonexistentTypes Silences the warning when trying to add resolvers for types that don't exist. Useful for optional extensions.
* @example
* exports.createResolvers = ({ createResolvers }) => {
* const resolvers = {
Expand Down

0 comments on commit 6b7ed63

Please sign in to comment.