0

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

TheSoul
  • 4,906
  • 13
  • 44
  • 74

1 Answers1

1

add "type" to resolver:

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