Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo Server 2.0: Allow `resolverValidationOptions` config #1075

Closed
loicplaire opened this issue May 20, 2018 · 11 comments

Comments

@loicplaire
Copy link

commented May 20, 2018

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.

@evans evans added this to the Release 2.0 milestone May 22, 2018
@evans

This comment has been minimized.

Copy link
Member

commented May 22, 2018

@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?

@loicplaire

This comment has been minimized.

Copy link
Author

commented May 27, 2018

@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.

@evans

This comment has been minimized.

Copy link
Member

commented May 30, 2018

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.

@alexanderte

This comment has been minimized.

Copy link

commented Oct 5, 2018

For others experiencing this issue – here is the fix:

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

This comment has been minimized.

Copy link

commented Oct 24, 2018

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

@SeanPercy

This comment has been minimized.

Copy link

commented Nov 21, 2018

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?

@danilobrinu

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2018

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}`);
@ghostganz

This comment has been minimized.

Copy link

commented Mar 8, 2019

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.

@danilobrinu

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

@ghostganz the right way is use makeExecutableSchema.

@khaledosman

This comment has been minimized.

Copy link

commented Oct 4, 2019

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?

@danilobrinu

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.