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

The __resolveType and __isTypeOf resolvers are never called #603

Open
lirbank opened this issue Mar 30, 2021 · 1 comment
Open

The __resolveType and __isTypeOf resolvers are never called #603

lirbank opened this issue Mar 30, 2021 · 1 comment

Comments

@lirbank
Copy link

lirbank commented Mar 30, 2021

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,
        };
      },
    },
  },
});
@michaeldgraham
Copy link
Collaborator

#608

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants