Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide IDs of affected items on GraphQL errors for list queries #463

Open
2 tasks
oe-bayram opened this issue Jan 7, 2023 · 3 comments
Open
2 tasks

Provide IDs of affected items on GraphQL errors for list queries #463

oe-bayram opened this issue Jan 7, 2023 · 3 comments
Labels
feature-request New feature or request GraphQL

Comments

@oe-bayram
Copy link

oe-bayram commented Jan 7, 2023

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
@AnilMaktala
Copy link
Member

Hi @oe-bayram, Thank you for raising this issue. Have you deleted the post using the data store?

@oe-bayram
Copy link
Author

No, I don't use the data store for deleting, storing or updating the items.

I use the graphqlOperation method from "aws-amplify" for this purpose:

import { API, graphqlOperation } from "aws-amplify";

export const deletePost = async (id: string): Promise<void> => {
  (await API.graphql(
    graphqlOperation(deletePostMutation, { input: { id } })
  )) as GraphQLResult<DeletePostMutation>;
};

But as I mentioned, for some reason, the comments of the post, were being deleted. So I know that I also have to delete all the comments before deleting the post.

But I used the Post and Comments example to simplify the example for explaining the issue.

In our case we have more than 90 entities in our GraphQL Schema with many connections between them. So sometimes when an error occurres during a deletion process, some of the data keeps in the database without their connections and it is difficult to identify these items.

Therefore it would be very helpful to get the list of items with error when calling a list query for this data model.

@AnilMaktala AnilMaktala added the feature-request New feature or request label Jan 17, 2023
@AnilMaktala
Copy link
Member

Hi @oe-bayram 👋, Thank you for providing the additional information. Labeled it as a feature request for the team to evaluate further 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request GraphQL
Projects
None yet
Development

No branches or pull requests

4 participants