如果在突变查询中添加列表类型,graphql 不会在 android 中编译

Posted

技术标签:

【中文标题】如果在突变查询中添加列表类型,graphql 不会在 android 中编译【英文标题】:graphql is not compiling in android if a list type is added in mutation query 【发布时间】:2018-12-12 10:40:53 【问题描述】:

我正在尝试使用具有列表和其他数据的输入构建突变查询,并且在编译时抛出错误。

这里 ItemData 是一个 list 类型,如果我 remove 它,则代码正在正确编译。

查询正在 AWS 内部进行验证 Screenchot of Query in AWS

我的 schema.graphql 如下所示

mutation AddAdHoc($doc_no: String!, $bag: Int!,  $cartons: Int!, $destination: String!, $pallets: Int!, $reason: String! ,$source: String!, $type: String!, $version: String, $itemData: ItemData)
addAdHocDetails(input: doc_no: $doc_no, bag: $bag, cartons: $cartons, destination: $destination, pallets: $pallets, reason: $reason ,source: $source, type: $type, version: $version, itemData: $itemData)
  
    id
 

我的 schema.json 的某些部分如下所示


              "name": "addAdHocDetails",
              "description": null,
              "args": [
                
                  "name": "input",
                  "description": null,
                  "type": 
                    "kind": "NON_NULL",
                    "name": null,
                    "ofType": 
                      "kind": "INPUT_OBJECT",
                      "name": "addAdHocInput",
                      "ofType": null
                    
                  ,
                  "defaultValue": null
                
              ],
              "type": 
                "kind": "OBJECT",
                "name": "TBLAdHoc",
                "ofType": null
              ,
              "isDeprecated": false,
              "deprecationReason": null
            

          "kind": "INPUT_OBJECT",
          "name": "addAdHocInput",
          "description": null,
          "fields": null,
          "inputFields": [
            
              "name": "doc_no",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "bag",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "cartons",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "destination",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "pallets",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "reason",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "source",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "type",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "version",
              "description": null,
              "type": 
                "kind": "SCALAR",
                "name": "String",
                "ofType": null
              ,
              "defaultValue": null
            ,
            
              "name": "itemData",
              "description": null,
              "type": 
                "kind": "LIST",
                "name": null,
                "ofType": 
                  "kind": "INPUT_OBJECT",
                  "name": "ItemData",
                  "ofType": null
                
              ,
              "defaultValue": null
            
          ],
          "interfaces": null,
          "enumValues": null,
          "possibleTypes": null
        ,

          "kind": "INPUT_OBJECT",
          "name": "ItemData",
          "description": null,
          "fields": null,
          "inputFields": [
            
              "name": "item_id",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "uom",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "String",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "qty",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            ,
            
              "name": "collectd",
              "description": null,
              "type": 
                "kind": "NON_NULL",
                "name": null,
                "ofType": 
                  "kind": "SCALAR",
                  "name": "Int",
                  "ofType": null
                
              ,
              "defaultValue": null
            
          ],
          "interfaces": null,
          "enumValues": null,
          "possibleTypes": null
        

任何帮助都是可观的,

提前致谢

【问题讨论】:

【参考方案1】:

我搞定了

ItemData的种类是List所以我们需要把数据放到[]中,这样才能列为列表输入

mutation AddAdHoc($doc_no: String!, $bag: Int!,  $cartons: Int!, $destination: String!, $pallets: Int!, $reason: String! ,$source: String!, $type: String!, $version: String, $itemData: [ItemData])
addAdHocDetails(input: doc_no: $doc_no, bag: $bag, cartons: $cartons, destination: $destination, pallets: $pallets, reason: $reason ,source: $source, type: $type, version: $version, itemData: $itemData)
  
    id
 

【讨论】:

以上是关于如果在突变查询中添加列表类型,graphql 不会在 android 中编译的主要内容,如果未能解决你的问题,请参考以下文章

如何在 sangria-graphql 中执行突变?

如何在 GraphiQL 中为 GraphQL 查询和突变添加名称?

FaunaDB - 如何批量更新单个 graphQL 突变中的条目列表?

如何在 GraphQL 中执行突变?

具有数组类型的 Graphql 突变

graphql 查询或突变能否返回标量值