question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ObjectType implementing InterfaceType doesn't end up in the schema

See original GitHub issue

Consider this code:

const {
  GraphQLID,
  GraphQLInterfaceType,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLSchema,
  printSchema,
} = require('graphql')

const NodeType = new GraphQLInterfaceType({
  name: 'Node',
  fields: {
    id: {
      type: new GraphQLNonNull(GraphQLID),
    },
  },
})

class Car {} // Kept brief for demo purpose

const CarType = new GraphQLObjectType({
  name: 'Car',
  interfaces: [NodeType],
  fields: {
    id: {
      type: new GraphQLNonNull(GraphQLID),
    },
  },
  isTypeOf: value => value instanceof Car,
})

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      node: {
        type: NodeType,
        args: {
          id: {
            type: new GraphQLNonNull(GraphQLID),
          },
        },
        resolve: () => new Car(),
      },
    },
  }),
})

console.log(printSchema(schema))

Which gives this output:

interface Node {
  id: ID!
}

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

This is a very simplified demo of the problem I’m running in to. Cars (in this case) don’t have their own queries so they don’t end up in the schema even though you can query for them by the interface they implement.

How can I make them appear in the printed schema?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
IvanGoncharovcommented, Jan 29, 2019

Fixed in #1679 by @buoyantair

2reactions
IvanGoncharovcommented, Jul 10, 2018

How can I make them appear in the printed schema?

@CrocoDillon You need to write this:

const schema = new GraphQLSchema({
  types: [CarType],
  query: new GraphQLObjectType({
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve interface type in GraphQL schema in test only
This implementation is not used (it uses the interface-specific resolve_type method) but satisfies the requirements of the validation check.
Read more >
sangria-graphql/sangria - Gitter
At first, I thought about using a field tag, to tag the field as a preview field, and overriding the fieldFn of the...
Read more >
Interfaces - GraphQL Ruby
If you add an object type which implements an interface, but that object type doesn't appear in your schema as a field return...
Read more >
Schemas and Types - GraphQL
Character is a GraphQL Object Type, meaning it's a type with some fields. Most of the types in your schema will be object...
Read more >
Interfaces | Side Quest: Intermediate Schema Design
Learn how to implement interface types in a GraphQL schema ... An implementing object type can also define any number of additional fields...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found