【问题标题】:GraphQL typedef mutation need to accept an ArrayGraphQL typedef 突变需要接受一个数组
【发布时间】:2019-02-17 18:59:10
【问题描述】:

在 GraphQL 中声明 typeDefs 时,如何在突变中传递自定义类型数组?

type Itinerary {
  name: String!
  itinerary: [Location]!
}

input Location {
  name: String!
  country: String
  region: String
  city: String
  duration: Int!
}

type Mutation {
  addItinerary(
    name: String!,
    itinerary: [Location]!,
  ): Itinerary
}

我在 graphiql “The type of Itinerary.itinerary must be Output Type but got: [Location]!”

这似乎是一项微不足道的任务,但我找不到与此案有关的任何具体内容

【问题讨论】:

    标签: javascript types graphql mutation


    【解决方案1】:

    您返回的类型为Itinerary,它本身包含一个嵌套的Location,但您已声明Location 是一个输入类型,无法返回作为突变的结果。需要定义单独的输入类型,不能返回。

    【讨论】:

    • 感谢您的回答,我不确定我是否正确理解您在说什么。你能举个例子吗?我需要将哪些字段声明为输入?感谢您的帮助
    • input Location input 表示您已将其声明为输入类型,因为仅可用于定义查询和突变的用户输入参数
    • 没错,Location 是用户输入,仅用于查询和变异。我仍在文档中搜索类似的示例,但找不到。在突变中将其作为数组参数传递的正确语法是什么?
    • 你说你的突变的返回类型是一个行程:): Itinerary
    猜你喜欢
    • 2019-11-04
    • 2017-05-05
    • 2021-09-10
    • 1970-01-01
    • 2020-02-03
    • 2019-02-07
    • 1970-01-01
    • 2017-04-03
    • 2017-01-21
    相关资源
    最近更新 更多