graphql-compose: TypeError: Cannot read property 'getTypeName' of undefined

1.8k Views Asked by At

I am trying out graphql-compose library and following their Getting started Github page, I build a very simple example.

Here is my code:

    import { schemaComposer } from "graphql-compose";

    export const UserTC = schemaComposer.createObjectTC({
      name: "UserTC",
      fields: {
        name: "String",
        surname: "String"
      }
    });

    UserTC.addResolver({
      kind: "query",
      name: "userFind",
      resolve: async () => {
       return []; // empty array
      }
    });

    schemaComposer.Query.addFields({
      userFind: UserTC.getResolver("userFind")
    });

    export const schema = schemaComposer.buildSchema()

I am getting the below error when I pass the returned schema object into
my Apollo server:

TypeError: Cannot read property 'getTypeName' of undefined

The error stack point to the last line of my code. I cannot figure out what I am doing wrong.

Thanks for your help.

I can possible not see what error I am doind

1

There are 1 best solutions below

1
maqon On BEST ANSWER

add "type" to resolver:

UserTC.addResolver({
  kind: "query",
  name: "userFind",
  type: UserTC,
  resolve: async () => {
   return []; // empty array
  }
});