【问题标题】:Creating multi variable GraphQL query创建多变量 GraphQL 查询
【发布时间】:2018-02-27 07:43:33
【问题描述】:

我一直在阅读和尝试很多东西,但只使用 cURL 作为工具。是否有其他方法针对 GraphQL 端点运行测试?

所以我的问题是带有多个变量的突变查询。这是我的 Shema 的一部分:

type mutation {
  oneComponentTypeCollected(userID: String!, password: String!, pageID: Int!,
    Components: ComponentsInput!): Page
}
type Components {
  ComponentType: ComponentType!
    required: Int!
    collected: Int!
}
type ComponentsInput {
  id: String!
    collected: Int!
}
type Page {
  id: Int!
}

我如何调用查询 oneComponentCollected 突变? 预期将收集的值设置为组件“inkpad_blue”的 1

我尝试了以下方法:

变量语法:

{"query":"mutation($input:ComponentsInput!) {oneComponentTypeCollected(userID: \"asd\", password: \"asd\", pageID: 1, input:$input){id}}","variables":{"input":{"id":"Inkpad_blue","collected":1}}} 

作为纯字符串:

mutation($input:ComponentsInput!) {oneComponentTypeCollected(userID: "asd", password: "asd", pageID: 1, input:$input){id}}

两者都会导致 500 个 HTTP 错误。

【问题讨论】:

    标签: javascript graphql graphql-js


    【解决方案1】:

    我认为你的突变应该是这样的

    mutation{oneComponentTypeCollected(userID: "asd", password: "asd", pageID: 1, Components:{"id": "Inkpad_blue","collected": 1}){id}}
    

    在你的 graphiql 中试试这个

    【讨论】:

      猜你喜欢
      • 2018-03-02
      • 2019-05-17
      • 2023-03-12
      • 2020-01-21
      • 2018-04-08
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多