javascript Graphql返回嵌套类型

xt0899hw  于 2023-03-21  发布在  Java
关注(0)|答案(1)|浏览(86)

我是graphql.js的新手,我正在尝试构建一个嵌套的graphql类型。
目前我有一个GameStatistic类型,我想有一个Statistic类型有两个字段与GameStatistic类型。

const gameStatisticType = new GraphQLObjectType({
  name: 'GameStatistic',
  fields: {
    id: { type: GraphQLString },
    wagered: { type: GraphQLFloat },
    profit: { type: GraphQLFloat },
  },
});

exports.Type = new GraphQLObjectType({
  name: 'Statistic',
  fields: {
    dice: new GraphQLObjectType(gameStatisticType),
    wheel: new GraphQLObjectType(gameStatisticType),
  },
});

但它一直给出"The type of Statistic.wheel must be Output Type but got: undefined.""The type of Statistic.dice must be Output Type but got: undefined."的误差
我到底做错了什么?

qzwqbdag

qzwqbdag1#

  • 不要再调用GraphQLObjectType,您已经有一个示例
  • 将类型放在描述字段的对象的.type属性中
exports.Type = new GraphQLObjectType({
  name: 'Statistic',
  fields: {
    dice: { type: gameStatisticType },
    wheel: { type: gameStatisticType },
  },
});

相关问题