0

Need help in Graphql Appsync

Appsync Custom Type :

type Employee {
        id: ID!
        name: String
        experiences: [Experiences]
        projects: [Projects]
}

Dynamo DB table Employee

Table: Employee
{
    id:’’,
    name:’’,
    experience:[
        {
            company:’’,
            from:’’,
            till:’’
        },
        {
            company:’’,
            from:’’,
            till:’’
        }
    ],
    projects:[

        {
            title:’’,
            date:’’

        },
        {
            title:’’,
            date:’’

         },
    ]

}

We need to update experience & Projects in 2 different mutation queries but update should be done in same dynamodb table. Here are my doubts:

  • Do need to create separate dynamodb table for Projects & Experience. How to write mutation queries for this table updating Projects & experience in diff mutation ?

1 Answer 1

1

let me try and answer your questions:

We need to update experience & Projects in 2 different mutation queries but update should be done in same dynamodb table.

You can create a single DataSource in AppSync, and have 2 mutations that resolve against this DataSource. This way, your mutations accept an array of Experience or Project types, and your resolver takes care of writing into this DynamoDB DataSource.

Do need to create separate dynamodb table for Projects & Experience.

This really depends on your usecase. Having separate DynamoDB tables helps you fetch the [1:N] related types using secondary indexes. Separate tables also help you paginate the related types instead of fetching all dependencies in a single call. If you end up using a single table to store Employee/Projects/Experience, refer to the Lists and Maps types section in the DynamoDB resolver.

How to write mutation queries for this table updating Projects & experience in diff mutation?

Like I mentioned, you would just define 2 mutations in your Schema that accept a list of types. In the resolver, you would write to appropriate tables. Please refer to the following documentation on DynamoDB Resolvers in AppSync.

Alternatively, you can also make use of DynamoDB Batch Resolver to write data into multiple tables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.