question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do i append an array in GraphQL through AppSync?

See original GitHub issue

For an ‘id’ in my DynamoDB table (e.g. e5eb02ae-04d5-4331-91e6-11efaaf12ea5), i have a column called Weather

['sun', 'rain', 'snow', etc...]

I need to update Weather when, say [‘hail’] arrives. Right now, my update() below, replaces the the entire array. All i want to do is append ‘hail’ to the end of that list.

    const updateinfo = {
       id: "e5eb02ae-04d5-4331-91e6-11efaaf12ea5",   
       Weather: "hail"
    }
    try {
        await API.graphql(graphqlOperation (UpdateInfo, { input: updateinfo }))  //mutation
        console.log('success')
       }
       catch (err) {
         console.log(err)
       }

How do i do this, ensuring that my list is just appended to with the info, WITHOUT having to get() and pull down [‘sun’, ‘rain’, ‘snow’, etc…], then adding ‘hail’ and creating a new array? Thats then a GetInfo() and an UpdateInfo() which is double the effort/call/expense.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
idanlocommented, Aug 16, 2019

@ajhool an array is definitely a standard thing that many many people use, this should absolutely be a feature that should work out of the box

6reactions
ajhoolcommented, Jul 30, 2019

Appending to an array field is definitely not standard logic and should be outside the scope of a framework like Amplify’s purview. The post by @nathan-quinn is incredibly helpful. Just use that

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS amplify graphql appsync - how to replace array instead ...
I am using AWS amplify with graphql and appsync. ... How can I replace my array with a new array, instead of appending...
Read more >
Resolver mapping template programming guide - AWS AppSync
In this tutorial, we demonstrate this by creating a simple GraphQL schema and passing a map of values to a Lambda function. The...
Read more >
Tutorial: Send an Array with GraphQL | by Andrew Larsen
Step 2 — Create your Input Type​​ This step looks nearly identical to Step 1, but is absolutely necessary in order to send...
Read more >
GraphQL List - How to use arrays in GraphQL schema ...
Applying array on GraphQL type. Implementing GraphQL modifiers. How to design mutations and queries with list of items as an argument and returned...
Read more >
Directly push to an array on DynamoDB entry with GraphQL ...
Is it possible to create a resolver in AppSync that takes an input (say an object) and pushes it on an existing array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found