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

How to create or delete multiple values at a time in a batch? #2873

Closed
janhesters opened this issue Mar 16, 2019 · 5 comments
Closed

How to create or delete multiple values at a time in a batch? #2873

janhesters opened this issue Mar 16, 2019 · 5 comments
Labels
AppSync Related to AppSync issues GraphQL Related to GraphQL API issues question General question

Comments

@janhesters
Copy link

** Which Category is your question related to? **
API

** What AWS Services are you utilizing? **
GraphQL, Dynamo DB, Codegen

** Provide additional details e.g. code snippets **
I have the following schema:

type Contact @model @auth(rules: [{ allow: owner }]) {
  id: ID!
  firstName: String!
  lastName: String!
  city: String
  company: String
  position: String
  group: Group!
  tendency: Tendency!
}

enum Group {
  innerFive
  friend
  confidant
  acquaintance
  distantAcquaintance
}

enum Tendency {
  rise
  maintain
  fall
}

This generated the following Graphql mutations for creating and deleting:

export const createContact = `mutation CreateContact($input: CreateContactInput!) {
  createContact(input: $input) {
    id
    firstName
    lastName
    city
    company
    position
    group
    tendency
  }
}
`;

export const deleteContact = `mutation DeleteContact($input: DeleteContactInput!) {
  deleteContact(input: $input) {
    id
    firstName
    lastName
    city
    company
    position
    group
    tendency
  }
}
`;

How can I delete or create in bulk? Let's say I have an array of ID's. What is the most efficient way to delete all users with those ID's?

@manueliglesias manueliglesias added question General question GraphQL Related to GraphQL API issues AppSync Related to AppSync issues labels Mar 18, 2019
@manueliglesias
Copy link
Contributor

Hi @janhesters

You can Add a custom resolver that targets a DynamoDB table from @model

Those docs mention writing more specific queries, but there is no reason it couldn't be adapted to do PUT operations / use DynamoDB Batch Resolvers.

You can construct your GraphQL mutations to accept a collection of ids and then implement the associated resolvers to perform batch operations.

I hope this helps. Also, if you want, you can creeate a feature request in the aws-amplify/amplify-cli repo

@janhesters
Copy link
Author

@manueliglesias Thank you for the answer. I will do that 👍

@LucasAndrad
Copy link

@jamesiri did you succeed with this approach? If yes, could you share your solution?

@PeteDuncanson
Copy link

@LucasAndrad and anyone else who stumbles on this, @janhesters wrote up their findings in this blog https://medium.com/@jan.hesters/creating-graphql-batch-operations-for-aws-amplify-with-appsync-and-cognito-ecee6938e8ee

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AppSync Related to AppSync issues GraphQL Related to GraphQL API issues question General question
Projects
None yet
Development

No branches or pull requests

4 participants