amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Provide IDs of affected items on GraphQL errors for list queries

Open oe-bayram opened this issue 2 years ago • 4 comments

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

No response

Describe the feature you'd like to request

Assume this GraphQL Schema:

type Post @model {
  id: ID!
  title: String!
  comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"])
}

type Comment @model {
  id: ID!
  postID: ID! @index(name: "byPost", sortKeyFields: ["content"])
  post: Post! @belongsTo(fields: ["postID"])
  content: String!
}

When for some reason a post has been deleted without deleting the comments of it and you query a list of comments, you get an error with following message:

Cannot return null for non-nullable type: 'Post' within parent 'Comment' (/listComments/items[7]/post)"

But you don't know which comments are affected.

Describe the solution you'd like

It would be helpful if the IDs of the affected items are also provided in the error object. Example:

{ 
  locations: null,
​​​  message: "Cannot return null for non-nullable type: 'Post' within parent 'Comment' (/listComments/items[7]/post)",
  items: ["0adbe6ed-c516-416c-b3ea-f0a0b352303c", "ed257824-f617-4449-9db3-18a36fe17b3b"],
​​  path: [ "listComments", "items", 7, "post"]
​​​​}

Describe alternatives you've considered

Identify comments without a post by using their IDs from the DynamoDB table and request a getOperation for each of them to check if an error occurs.

Additional context

No response

Is this something that you'd be interested in working on?

  • [ ] 👋 I may be able to implement this feature request
  • [ ] ⚠️ This feature might incur a breaking change

oe-bayram avatar Jan 07 '23 18:01 oe-bayram