【问题标题】:Add custom input type to graphql-tag mutation将自定义输入类型添加到 graphql-tag 突变
【发布时间】:2020-11-19 14:56:54
【问题描述】:

我的 django 突变将 data 变量作为 graphene.JSONString() 传递,所以我的 $data 变量需要是 JSON 或 Object 类型。这里有什么方法可以实现吗?

我尝试使用标量 JSON,但出现错误

我在使用时遇到错误:$data: JSON!

export const UPLOAD_SPECIFICATION = gql`
scalar JSON
mutation ($account_id: String!, $name: String, $description: String, $data: JSON!){
    uploadSpecification(account_id: $account_id, name:$name, description: $description, data: $data) {
        specification {
            id,
            name
        }
    }
}`; 

【问题讨论】:

    标签: json object apollo apollo-client mutation


    【解决方案1】:
    export const UPLOAD_SPECIFICATION = gql`
    mutation ($account_id: String!, $name: String, $description: String, $data: JSONObject){
        uploadSpecification(account_id: $account_id, name:$name, description: $description, data: $data) {
            specification {
                id,
                name
            }
        }
    }`; 
    

    我的 schema.graphql 中需要标量:

    scalar JSON
    scalar JSONObject
    
    type Mutation{
    uploadSpecification(..., data: JSONObject):Specification
    
    }
    
    

    【讨论】:

      猜你喜欢
      • 2017-09-18
      • 2018-02-22
      • 2020-01-31
      • 1970-01-01
      • 2019-05-14
      • 2018-10-19
      • 2020-05-23
      • 2018-09-14
      • 2020-03-21
      相关资源
      最近更新 更多