"Cannot return null for non-nullable type: 'ID' within parent 'MasterBom' (/queryMasterBomWithin/id)"

71 Views Asked by At

so i have the model like this :

 type MasterBom @model @auth(rules:[{allow:groups,groups:["admin","handler"]}]){
  id:ID!
  clientName:String!
  clientId:ID! @index(name: "byClientId", sortKeyFields: ["arriveDate"], queryField: "sortByArriveDate")
  client: Client @belongsTo (fields:["clientId"])
  DetailBoms: [DetailBom] @hasMany
  expectedArrivalDate:Float
  arriveDate :Float
  senderName: String
  checkerName: String
  statusBom:String @index(name:"byStatusClient", sortKeyFields:["expectedArrivalDate"],queryField:"byExpectedArrival")
}

the query like this:

type Query{
  queryMasterBomWithin(status:String!,startDate:Float!,endDate:Float!):MasterBom
}

with resolver request template like this :

{
        "version": "2018-05-29",
        "operation": "Query",
        "query":{
        "expression":"statusBom=:status AND expectedArrivalDate BETWEEN :startDate AND :endDate",
        "expressionValues":{
        ":status":$util.dynamodb.toDynamoDBJson($ctx.args.status),
        ":startDate":$util.dynamodb.toDynamoDBJson($ctx.args.startDate),
        ":endDate":$util.dynamodb.toDynamoDBJson($ctx.args.endDate)
                            }
                  },
        "index":"byStatusClient"
        
      } 

and resolver response like this:

$util.toJson($ctx.result.items)

and i got and error like this:

{
  "data": {
    "queryMasterBomWithin": null
  },
  "errors": [
    {
      "path": [
        "queryMasterBomWithin",
        "id"
      ],
      "locations": null,
      "message": "Cannot return null for non-nullable type: 'ID' within parent 'MasterBom' (/queryMasterBomWithin/id)"
    }
  ]
}

After i use tracing log, the request succesfully with log like this ;

{
    "logType": "RequestMapping",
    "path": [
        "queryMasterBomWithin"
    ],
    "fieldName": "queryMasterBomWithin",
    "resolverArn": "arn:aws:appsync:ap-southeast-1:716328346449:apis/uu7f3j6bcfcv5ai5rldiv3ibuy/types/Query/resolvers/queryMasterBomWithin",
    "requestId": "52662f3a-6906-4140-acc6-72b429c8930b",
    "context": {
        "arguments": {
            "status": "dockA",
            "startDate": 17000,
            "endDate": 18008958059225
        },
        "stash": {},
        "outErrors": []
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query",
    "graphQLAPIId": "uu7f3j6bcfcv5ai5rldiv3ibuy",
    "transformedTemplate": "\n{\n        \"version\": \"2018-05-29\",\n        \"operation\": \"Query\",\n        \"query\":{\n        \"expression\":\"statusBom=:status AND expectedArrivalDate BETWEEN :startDate AND :endDate\",\n        \"expressionValues\":{\n        \":status\":{\"S\":\"dockA\"},\n        \":startDate\":{\"N\":17000.0},\n        \":endDate\":{\"N\":1.8008958059225E13}\n                            }\n                  },\n        \"index\":\"byStatusClient\"\n        \n      } \n"
}

but got also succesfully from response template from the log like this :

{
    "logType": "ResponseMapping",
    "path": [
        "queryMasterBomWithin"
    ],
    "fieldName": "queryMasterBomWithin",
    "resolverArn": "arn:aws:appsync:ap-southeast-1:716328346449:apis/uu7f3j6bcfcv5ai5rldiv3ibuy/types/Query/resolvers/queryMasterBomWithin",
    "requestId": "52662f3a-6906-4140-acc6-72b429c8930b",
    "context": {
        "arguments": {
            "status": "dockA",
            "startDate": 17000,
            "endDate": 18008958059225
        },
        "result": {
            "items": [
                {
                    "clientId": "433af92f-ffd8-4041-b575-bbb8a8477e19",
                    "clientName": "Charoen Popkhand",
                    "_lastChangedAt": 1700982291528,
                    "__typename": "MasterBom",
                    "arriveDate": 1700982290737,
                    "createdAt": "2023-11-25T03:25:35.069Z",
                    "senderName": "arif",
                    "statusBom": "dockA",
                    "expectedArrivalDate": 1700956800000,
                    "checkerName": "marendra",
                    "id": "1e50d802-15c7-4bbb-ada3-19b5fa8f426c",
                    "clientMasterBomsId": "433af92f-ffd8-4041-b575-bbb8a8477e19",
                    "_version": 2,
                    "updatedAt": "2023-11-26T07:04:51.507Z"
                },
                {
                    "createdAt": "2023-11-25T07:03:25.882Z",
                    "clientId": "433af92f-ffd8-4041-b575-bbb8a8477e19",
                    "statusBom": "dockA",
                    "clientName": "Charoen Popkhand",
                    "_lastChangedAt": 1700895805922,
                    "expectedArrivalDate": 1701043200000,
                    "__typename": "MasterBom",
                    "id": "8efba672-2802-453a-b53d-36481ba9ade1",
                    "clientMasterBomsId": "433af92f-ffd8-4041-b575-bbb8a8477e19",
                    "_version": 1,
                    "updatedAt": "2023-11-25T07:03:25.882Z"
                }
            ],
            "scannedCount": 2
        },
        "stash": {},
        "outErrors": []
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query",
    "graphQLAPIId": "uu7f3j6bcfcv5ai5rldiv3ibuy",
    "transformedTemplate": "\n{\n    \"items\": [{\"clientId\":\"433af92f-ffd8-4041-b575-bbb8a8477e19\",\"clientName\":\"Charoen Popkhand\",\"_lastChangedAt\":1700982291528,\"__typename\":\"MasterBom\",\"arriveDate\":1700982290737,\"createdAt\":\"2023-11-25T03:25:35.069Z\",\"senderName\":\"arif\",\"statusBom\":\"dockA\",\"expectedArrivalDate\":1700956800000,\"checkerName\":\"marendra\",\"id\":\"1e50d802-15c7-4bbb-ada3-19b5fa8f426c\",\"clientMasterBomsId\":\"433af92f-ffd8-4041-b575-bbb8a8477e19\",\"_version\":2,\"updatedAt\":\"2023-11-26T07:04:51.507Z\"},{\"createdAt\":\"2023-11-25T07:03:25.882Z\",\"clientId\":\"433af92f-ffd8-4041-b575-bbb8a8477e19\",\"statusBom\":\"dockA\",\"clientName\":\"Charoen Popkhand\",\"_lastChangedAt\":1700895805922,\"expectedArrivalDate\":1701043200000,\"__typename\":\"MasterBom\",\"id\":\"8efba672-2802-453a-b53d-36481ba9ade1\",\"clientMasterBomsId\":\"433af92f-ffd8-4041-b575-bbb8a8477e19\",\"_version\":1,\"updatedAt\":\"2023-11-25T07:03:25.882Z\"}],\n    \"nextToken\": null\n}"
}

and an error :

{
    "logType": "GraphQLFieldRuntimeError",
    "fieldInError": true,
    "path": [
        "queryMasterBomWithin",
        "id"
    ],
    "errors": [
        "Cannot return null for non-nullable type: 'ID' within parent 'MasterBom' (/queryMasterBomWithin/id)"
    ],
    "requestId": "52662f3a-6906-4140-acc6-72b429c8930b",
    "graphQLAPIId": "uu7f3j6bcfcv5ai5rldiv3ibuy"
}

but still got an error from the query, could someone help me? why the appsync spit out an error ?

Many Thanks

Arif marendra

1

There are 1 best solutions below

0
On

okay i figured out.

just change type query to become like this:

type Query{
  queryMasterBomWithin(status:String!,startDate:Float!,endDate:Float!):[MasterBom]
}

because i forgot the return was an array!