Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

The __resolveType and __isTypeOf resolvers are never called #603

Open
@lirbank

Description

@lirbank

Consider the contrived example below.

  • If I replace makeAugmentedSchema with makeExecutableSchema then everything works as expected.
  • The __resolveType resolver is never called when using makeAugmentedSchema, but is called as expected when makeExecutableSchema is used.
  • If I use makeExecutableSchema and comment out the __resolveType resolver, then it produces the same error as makeAugmentedSchema does in either case (see error below).
  • Using a __isTypeOf resolver has the same issue (is never called with makeAugmentedSchema).
  • Changing the ids to something else, as this issue suggests, doesn't help.

Query:

query Vehicle {
  vehicle {
    __typename
    id
  }
}

Error:

"Abstract type "Vehicle" must resolve to an Object type at runtime for field "Query.vehicle". Either the "Vehicle" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."

Schema:

// import { makeExecutableSchema } from 'apollo-server-express';
import { makeAugmentedSchema } from 'neo4j-graphql-js';

export const schema = makeAugmentedSchema({
  typeDefs: /* GraphQL */ `
    interface Vehicle {
      id: ID!
    }

    type Truck implements Vehicle {
      id: ID!
      payload: Int
    }

    type Bus implements Vehicle {
      id: ID!
      passengers: Int
    }

    type Query {
      vehicle: Vehicle
    }
  `,

  resolvers: {
    Vehicle: {
      __resolveType(vehicle: { readonly type: 'Truck' | 'Bus' }) {
        console.log('__resolveType', vehicle);
        return vehicle.type;
      },
    },

    Truck: {
      id() {
        console.log('Truck ID');
        return 'Truck ID';
      },
    },

    Bus: {
      id() {
        console.log('Bus ID');
        return 'Bus ID';
      },
    },

    Query: {
      vehicle() {
        const type = Math.random() > 0.5 ? 'Truck' : 'Bus';
        console.log('type', type);

        return {
          type,
        };
      },
    },
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions