Prisma1: Type "Node" is missing a "resolveType" resolver.

Created on 17 Apr 2018  路  23Comments  路  Source: prisma/prisma1

I am not sure this is a bug. I use Prisma init my project. select typescript-advanced. When I yarn start I always found this console "Type "Node" is missing a "resolveType" resolver. Pass false into ".

I doubt it because I do not yet edit the file but its show this console.

screen shot 2561-04-17 at 15 31 48

kindiscussion bu0-needs-info

Most helpful comment

So while the option turns it off, is there a nice explanation somewhere of what the warning was for?

How and why would I implement resolveType so I wouldn't have to turn the option off?

I want to have a good understanding to explain to my students.

Thanks in advance.

All 23 comments

It's just a warning. To hide it add the resolverValidationOptions in the schema:

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

Thanks for bringing this up @vistriter, and your suggested fix @gsancho! 馃檶

I'll keep this issue open for a bit to keep the discussion going, and to see if there are other things that should be adjusted.

Thank you! @gsancho. Now, It's not have warned. I will let you know if have a new problem. @marktani

Same issue. FYI

Suggested solution doesnt work in this case:

const { GraphQLServer } = require('graphql-yoga');
const { Prisma } = require('prisma-binding');

const resolvers = {
  Query: {
    feed(parent, args, ctx, info) {
      return ctx.db.query.posts({ where: { isPublished: true } }, info);
    },
    drafts(parent, args, ctx, info) {
      return ctx.db.query.posts({ where: { isPublished: false } }, info);
    },
    post(parent, { id }, ctx, info) {
      return ctx.db.query.post({ where: { id: id } }, info);
    }
  },
  Mutation: {
    createDraft(parent, { title, text }, ctx, info) {
      return ctx.db.mutation.createPost({ data: { title, text, isPublished: false } }, info);
    },
    deletePost(parent, { id }, ctx, info) {
      return ctx.db.mutation.deletePost({ where: { id } }, info);
    },
    publish(parent, { id }, ctx, info) {
      return ctx.db.mutation.updatePost(
        {
          where: { id },
          data: { isPublished: true }
        },
        info
      );
    }
  }
};

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  **resolverValidationOptions: {
    requireResolversForResolveType: false
  },**
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: 'src/generated/prisma.graphql',
      endpoint: 'http://localhost:4466/my-app/dev',
      secret: 'mysecret123',
      debug: true
    })
  })
});

Same issue.

As with @idkjs, the suggested solution doesn't work for me either, I'm afraid. I still get the warning.

Code is shown below:

const { GraphQLServer } = require('graphql-yoga');
const { Prisma } = require('prisma-binding');



const resolvers = {
  Query: {
    info: () => 'This is the API of a Hackernews clone',
    // info: () => null,
    feed: (root, args, context, info) => {
      return context.db.query.links({}, info);
    },

  },


  Mutation: {
    post: (root, args, context, info) => {
      return context.db.mutation.createLink({
        data: {
          url: args.url,
          description: args.description,
        },
      }, info)
    },
  }
}

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  resolverValidationOptions :{
    requireResolversForResolveType: false
  },
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: 'src/generated/prisma.graphql',
      endpoint: 'https://eu1.prisma.sh/some-random-stuff-here/hackernews-node/dev',
      secret: 'mysecret123',
      debug: true,
    }),
  }),
});


server.start(() => console.log('Server is running on http://localhost:4000'));

As with @expatia and @idkjs I am getting the same warning.

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  resolverValidationOptions :{
    requireResolversForResolveType: false
  },
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: 'src/generated/prisma.graphql',
      endpoint: 'https://us1.prisma.sh/some-random-stuff/todo-node/dev',
      secret: 'mysecret123',
      debug: true,
    }),
  }),
})
server.start(() => console.log(`Server is running on http://localhost:4000`))

I'm getting this error too when running my tests and this option is abstracted away in a package

Can you elaborate on how it is abstracted away, @wesbos?

There's a pending PR to add the respective option to graphql-yoga, would that help? https://github.com/graphcool/graphql-yoga/pull/270

I'm using graphql-mock in my tets - I guess I will have to PR that option over there as well

Just upated Prisma from 1.1.3 to 1.6.3 and this warning started to appear when I run yarn run dev

Having the same problem..

The just released version 1.12.0 of graphql-yoga ships with the functionality of passing the resolverValidationOptions while creating the GraphQLServer instance. Passing requireResolversForResolveType: false will eliminate the warning you've encountered before.

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  resolverValidationOptions: {
    requireResolversForResolveType: false
  }
});

Cool. Thank you!

Thanks for the PR, @akoenig 馃檶

This looks like it's only been implemented in GraphQLServer.... I still get these warnings when using GraphQLServerLambda :(

Thanks @abelovic! Please bring this up here: https://github.com/graphcool/graphql-yoga 馃檪

const schema = makeExecutableSchema({ typeDefs: importSchema("./src/schema.graphql"), resolvers, resolverValidationOptions :{ requireResolversForResolveType: false }, directiveResolvers })
passing resolverValidationOptions, worked for me. Thanks.

So while the option turns it off, is there a nice explanation somewhere of what the warning was for?

How and why would I implement resolveType so I wouldn't have to turn the option off?

I want to have a good understanding to explain to my students.

Thanks in advance.

@jeffbski: I don't have a full grasp on the details, but my rudimentary understanding is that it stems from the difference between the Prisma server and the application GraphQL server. Specifically, I believe that the error indicates an absence of resolvers in the _application server_ for types in the _Prisma server._ Of course, those resolvers are often not necessary as not every Prisma type needs to be functional on the application side.

In trying to dig up some info., I read the bottom of this ReadMe:

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.

and, more descriptively, this post!

All the other GraphQL interfaces from the GraphQL server schema (which is the entire schema and not only a part of it as before) are not resolved. But you don鈥檛 need to resolve them, because they are not used in your actual GraphQL queries and mutations in your application. Thus, you can deactivate these warnings.

@jangerhofer

Your comment is accurate, with this small adjustment:

Specifically, I believe that the error indicates an absence of resolvers in the application server for types in the Prisma server.

The warning is specifically about the Node _interface_ (not _type_).


You can also implement Node resolver to make this warning go away, instead of disabling the warning.

@marktani how would you implement the Node interface as a resolver?

@jeffbski I got some insight here.

When you have a field in your schema that returns a union or interface type, you will need to specify an extra __resolveType field in your resolver map, which tells the GraphQL executor which type the result is, out of the available options.

Check out the example that follows.

If anyone, like me, actually wants to implement the Node functionality provided in the Prisma API - in the front API (it gives you the ability to search for any type just by ID, and optionally return different data set by using one or more fragments, of the correct type - sample below)

[so basically the same query can return different data based on the actual type ]

I'm assuming that you are seeing references to Node because you have 'comment imported' a type that uses the Node interface from prisma

i.e you have this in your schema.graphql file (assuming running one of the boilerplate projects from prisma):
# import Post from **"./src/generated/prisma.graphql"

Prisma's types implement the Node interface, so after making the executable schema this will have been imported to your API schema:

type Post implements Node {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  isPublished: Boolean!
  title: String!
  text: String!
  author(where: UserWhereInput): User!
}

For this example you will also want to change the User type in your schema.graphql to implement Node, like so:

type User implements Node {
  id: ID!
  email: String!
  name: String!
  posts: [Post!]!
}

You can then implement Node functionality in your API to actually make use of it like this:

schema.graphql
add the following Query along with whatever else you have

type Query {
    node(id: ID!): Node
}

resolver.file.js/ts
In one of your resolver files, add both of these resolvers, one for node, and a special one similar to that described here
https://github.com/apollographql/graphql-tools/blob/master/docs/source/resolvers.md
I've tweaked it to get it to work without having to manually specify every type that could be returned (thanks to the fact that we actually call 'node' on the prisma api for the data which returns the actual type in the response)

Query: {
    node (parent, { id }, ctx, info) {
      return ctx.db.query.node({ id }, info)
    },
  },
Node: {
    __resolveType (obj, ctx, info) {
      return obj.__typename
    }
  },

Once you have that up and running, you can post the following via GraphQL Playground to try it out, take an actual id of something in your database.
In order to get this to work, User (a type specified in the API Schema) also has to implement Node

fragment NodePostFragment on Post{
  id
  title
  isPublished
}
fragment NodeUserFragment on User{
  id
  name
  email
}
query {
   node(id: "cjkvah3cq000x0768lxssul3e") {
       ...NodePostFragment
       ...NodeUserFragment
  }
}

Now say that the ID passed in is actually for a Post, you'd get this response, with only fields from the Post fragment.

{
  "data": {
    "node": {
      "id": "cjkvah3cq000x0768lxssul3e",
      "title": "Hello World 馃憢",
      "isPublished": true
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wereHamster picture wereHamster  路  37Comments

marktani picture marktani  路  34Comments

schickling picture schickling  路  36Comments

marktani picture marktani  路  48Comments

schickling picture schickling  路  44Comments