Apollo-server: Apollo Server 2.0: Allow `resolverValidationOptions` config

Created on 21 May 2018  ·  12Comments  ·  Source: apollographql/apollo-server

With Apollo Server 2.0, we can't provide resolverValidationOptions to the constructor to be passed down to makeExecutableSchemain apollo-server-core.

In my current project using Prisma, I need to be able to set it to resolverValidationOptions.requireResolversForResolveType (reference) to prevent the following warning to be displayed:

Type "Node" is missing a "resolveType" resolver. Pass false into "resolverValidationOptions.requireResolversForResolveType" to disable this warning.

We could do something very similar to what graphql-yoga recently added.

⛲️ feature 📚 good-first-issue

Most helpful comment

For others experiencing this issue – here is the fix:

const resolvers = {
  Query: {
    // …
  },
  Node: {
    __resolveType() {
      return null;
    }
  }
};

All 12 comments

@loicplaire Thank you for the issue! The current solution for this would be to add a __resolveType for Node in the resolvers, as seen in the docs on unions. The other option would be to create a schema directly with makeExecutableSchema and pass that into the server construction.

Apollo Server 2 aims to make the defaults follow best practices, such as defining type resolution for unions/interfaces. I'm not sure it would be appropriate to include an option for resolverValidationOptions, since the makeExecutableSchema defaults inform best practice. Curious about your thoughts?

@evans thanks for your answer and all the info! I think your point about the defaults following best practices make sense and I am happy for that bug to be closed as this can be solved by adding the __resolveType for Node.

Glad to hear it! Seems like the warning message adds more confusion than help. If you're up for it, adding __ to the warning message here in graphql-tools might make things more clear.

For others experiencing this issue – here is the fix:

const resolvers = {
  Query: {
    // …
  },
  Node: {
    __resolveType() {
      return null;
    }
  }
};

Do you have an example for the schema for this @alexanderte please?

Faced the same issue. Here is how to fix it, according to the the warning.

const executableSchema = makeExecutableSchema({
    typeDefs,
    resolvers,
    resolverValidationOptions: {
        requireResolversForResolveType: false,
    },
});

@ahmedu007 do you mean this?

You can use makeExecutableSchema to hide the warning passing false to resolverValidationOptions.requireResolversForResolveType this is the way to work with prisma-binding

const { ApolloServer, makeExecutableSchema } = require('apollo-server');
const { Prisma } = require('prisma-binding');
const { importSchema } = require('graphql-import');

const typeDefs = importSchema('./src/schema.graphql');
const resolvers = require('./resolvers');
const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
  resolverValidationOptions: { requireResolversForResolveType: false },
});

const server = new ApolloServer({
  schema,
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql', // the auto-generated GraphQL schema of the Prisma API
      endpoint: process.env.PRISMA_ENDPOINT, // the endpoint of the Prisma API
      debug: true, // log all GraphQL queries & mutations sent to the Prisma API
      // secret: process.env.PRISMA_SECRET, // only needed if specified in `database/prisma.yml`
    }),
  }),
});

server.listen().then(({ url }) => `🚀  Server ready at ${url}`);

It would still be useful to be able to pass resolver options through the ApolloServer constructor.

It could be a single config entry to intentionally silence a warning, but now I either have to stub a lot of unused __resolveType methods or refactor the server setup to use the makeSchema method.

@ghostganz the right way is use makeExecutableSchema.

Ran into this issue because I'm using an interface, why is this warning thrown and what's the right way to handle it?

Setting the option to false in makeExecutableSchema or adding a resolverType resolver that returns null, sound like just workarounds to silence the warning? What's the actual recommended solution or why is this warning thrown in first place?

@khaledosman by default the apollo server use the __resolverType to handle all types in the app and the base type is Node, this type is implemented by each type in the app. Apollo just show a warning because in the default behaviour is required but this is not valid when your create a custom server with your own types.

So to hide this warnings you can use makeExecutableSchema for that.

I think that either ApolloConfig should allow for these options, or ApolloConfig should require schema and this should always just be used directly.

Was this page helpful?
0 / 5 - 0 ratings