Ankur Kumar
Ankur Kumar

Reputation: 1

Graphql Mutation query for DynamoDB table having Custom Type attribute

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:

Upvotes: 0

Views: 500

Answers (1)

Shankar Raju
Shankar Raju

Reputation: 4546

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.

Upvotes: 1

Related Questions