Graphql-js: Error: Generated Schema cannot use Interface or Union types for execution

Created on 24 Nov 2016  路  1Comment  路  Source: graphql/graphql-js

I try to implement the relay example from https://facebook.github.io/relay/docs/graphql-relay-specification.html#content

In the example the query contains a node which is a interface. I try to do the same but getting

Error: Generated Schema cannot use Interface or Union types for execution.
at GraphQLInterfaceType.cannotExecuteSchema [as resolveType] (/Users/myProject/node_modules/graphql/utilities/buildASTSchema.js:476:9)
at completeAbstractValue (/Users/myProject/node_modules/graphql/execution/execute.js:649:57)
at completeValue (/Users/myProject/node_modules/graphql/execution/execute.js:592:12)
at /Users/myProject/node_modules/graphql/execution/execute.js:554:14
at process._tickCallback (internal/process/next_tick.js:103:7)

Schema

interface Node {
    id: ID!
}

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

type User implements Node {
    id: ID!
    givenName: String
    familyName: String
}

Query

query{node(id:"eyJrZXkiOiJ1c2VyIiwidmFsdWUiOjF9"){
  id
  ...myFragment
}}

fragment myFragment on User {
    familyName
}

Query Result (GraphIQL)

{
  "data": {
    "node": null
  },
  "errors": [
    {
      "message": "Generated Schema cannot use Interface or Union types for execution.",
      "locations": [
        {
          "line": 1,
          "column": 7
        }
      ],
      "path": [
        "node"
      ]
    }
  ]
}

What am i missing here?

Most helpful comment

Turned out i needed to define a resolver for Node. Ive done this using graphql-tools as mentioned
here http://dev.apollodata.com/tools/graphql-tools/resolvers.html

>All comments

Turned out i needed to define a resolver for Node. Ive done this using graphql-tools as mentioned
here http://dev.apollodata.com/tools/graphql-tools/resolvers.html

Was this page helpful?
0 / 5 - 0 ratings