0
votes

Using apollo-server, if I attempt to define a graphql resolver that does not exist in my schema, the computer yells at me.

[Error: Query.foo defined in resolvers, but not in schema]

This is good!

Is it possible, using the apollo (or other?) tools, to do the opposite? That is, is there a way to have apollo tell me if there's a query, mutation, or subscription operation that's defined in my schema but not defined in my resolvers?

1

1 Answers

1
votes

There's an optional resolverValidationOptions object that can be passed to makeExecutableSchema to enforce some additional resolver validations as shown here:

  • requireResolversForArgs will cause makeExecutableSchema to throw an error if no resolve function is defined for a field that has arguments.
  • requireResolversForNonScalar will cause makeExecutableSchema to throw an error if a non-scalar field has no resolver defined. Setting this to true can be helpful in catching errors, but defaults to false to avoid confusing behavior for those coming from other GraphQL libraries.
  • requireResolversForAllFields asserts that all fields have a valid resolve function.
  • requireResolversForResolveType will require a resolveType() method for Interface and Union types. This can be passed in with the field resolvers as __resolveType(). False to disable the warning.
  • allowResolversNotInSchema turns off the functionality which throws errors when resolvers are found which are not present in the schema. Defaults to false, to help catch common errors.

None of them specifically targets only fields on the root types, but you may be able to make use of one or more.

These options are not exposed directly through ApolloServer, but you can always do:

const schema = makeExecutableSchema({ typeDefs, resolvers, resolverValidationOptions })
const apollo = new ApolloServer({ schema })