【问题标题】:GraphQL - Field "x" of type "[User]" must have a selection of subfields. Did you mean "x{ ... } [duplicate]GraphQL - “[用户]”类型的字段“x”必须有一个子字段选择。您的意思是“x{ ... } [重复]
【发布时间】:2021-01-09 22:49:10
【问题描述】:

我正在尝试获取以下简单查询:

{duel{id, players}}

我收到以下错误:

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

我的决斗类型结构:

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) },
  }),
});

知道我错过了什么吗?

谢谢。

【问题讨论】:

    标签: javascript node.js graphql graphql-js


    【解决方案1】:

    您必须为players 列表中的每个项目指定要获取的UserType 中的字段。假设 UserType 有一个 name 字段,此示例可能适用于您的用例:

    {
      duel {
        id,
        players {
          name
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-09
      • 2019-10-02
      • 1970-01-01
      • 2019-05-23
      • 2020-06-17
      • 1970-01-01
      相关资源
      最近更新 更多