graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Add resolverValidationOptions parameter to addMocksToSchema

Open sachinnash opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

I am dynamically generating resolvers from a schema. These resolvers are then passed as parameters to addMocksToSchema:

  const server = new ApolloServer({
    schema: addMocksToSchema({
      schema: makeExecutableSchema({ typeDefs: typeDefs }),
      mocks: mocks,
      resolvers: generatedResolvers
    }),
  });

Internally, these are passed to addResolversToSchema (in graphql-tools/schema), which fails with the error ${typeName}.${fieldName} defined in resolvers, but not in schema. This failure can be avoided by sending resolverValidationOptions = { requireResolversToMatchSchema: 'ignore'/'warn' } to addResolversToSchema.

To achieve this, we need to add the resolverValidationOptions parameter to addMocksToSchema, which will then pass it to addResolversToSchema.

Describe the solution you'd like

Modify the addMocksToSchema definition to accept a resolverValidationOptions parameter. This parameter will be passed to addResolversToSchema.

Describe alternatives you've considered

Manually filtering out the extra resolvers from the generatedResolvers - very much prone to failure.

Additional context

sachinnash avatar Jul 11 '24 13:07 sachinnash