如何将变量传递给此graphql

时间:2018-05-22 23:43:07

标签: graphql graphql-js

我有这个GraphQL,它可以工作,但当我尝试把变量放在工作中

mutation serviceOrder {
  serviceOrderCreate(input: {data: {
    needsTo: "string",
    problemDescription: "string",
    profession: {},
    responseTime: "2018-05-22T05:08:04.154Z",
    address: {},
    insurance: "string",
    insurance_code: "string",
    personId: 1,
    userId: 1
}}) {
    clientMutationId
    obj {
      id
      user {
        firstName
      }
    }
  }
}

这是变量但不起作用,有什么帮助吗?   我的突变看起来像这样:

mutation serviceOrder(
  $needsTo:String!
  $problemDescription:String!
  $profession:String!
  $responseTime:String!
  $address:String!
  $insurance:String!
  $insurance_code:String!
  $personId:ID!
  $userId:ID!
    ) {
  serviceOrderCreate(input: {
    data:{
      needsTo: $needsTo,
      problemDescription:$problemDescription,
      profession: $profession ,
      responseTime: $responseTime,
      address:$address,
      insurance:$insurance ,
      insurance_code:$insurance_code ,
      personId:$personId,
      userId: $userId
}
  }) {
    clientMutationId
    obj {
      id
      profession
      user{
        lastName
      }
    }
  } 
}

但是它给了我错误:" serviceOrder实例无效。详细信息:needsTo不能为空(值:null); problemDescription不能为空(值:null); profession不能为空(值:null); responseTime不能为空(值:null); address不能为空(值:null); insurance不能为空(值:null)。",

更新: 这就是我修复变异的方法

    mutation serviceOrder($input: JSON) {
      serviceOrderCreate(input: {data: $input}) {
        obj {
          problemDescription
          user{
            lastName
          }
        }
      }

}

将此传递为变量

{
    "input": {
      "needsTo": "Clinical embryologist",
        "problemDescription": "Father fear wish head laugh rule physical TV.",
        "profession": "Accommodation manager",
        "responseTime": "2018-05-22T19:03:05.229Z",
        "address": "3070 Patrick Overpass Apt. 070\nJamesfort, SC 14607",
        "insurance": "true",
        "insuranceCode": "string",
        "personId": 1,
        "userId": 1
    }
}

0 个答案:

没有答案