Search code examples
javascriptnode.jsgraphqlgraphql-js

GraphQL - Field "x" of type "[User]" must have a selection of subfields. Did you mean "x{ ... }


I'm trying to get the following simple query:

{duel{id, players}}

and I get the following error:

Field "players" of type "[User]" must have a selection of subfields. Did you mean "players { ... }

My Duel type structure:

const DuelType = new ObjectType({
  name: 'Duel',
  fields: () => ({
    id: { type: new NonNull(ID) },
    round_id: { type: IntType },
    status: { type: StringType },
    turn_of_user_id: { type: IntType },
    winner: { type: StringType },
    players: { type: new GraphQLList(UserType) },
  }),
});

Any idea what I'm missing?

Thanks.


Solution

  • You must specify the fields in UserType you want to get for each item in the players list. Assuming UserType has a name field, this example could work for your use case:

    {
      duel {
        id,
        players {
          name
        }
      }
    }