I am building an AWS AppSync graphQL server connected to DynamoDB which is using composite keys (let's say postID which is totally unique for my HASH and clientID for my RANGE).
GraphQL specs ask for a unique ID.
In order for me to fetch an item from DynamoDB I need to pass it both. How should I handle the schema in order to follow the graphQL specs?
Would I create the graphQL ID build from postID+clientID? Is there a standardized way?
It may be possible to I am overreading the specs and that it's totally fine to always require the clientID to be also passed for queries and mutation but I could not find a definitive answer. I have not yet worked with Relay so I am uncertain of what it sends back and forth.
Yes, it is fine in AppSync to require the clientId.
See the AppSync Docs on designing a schema: https://docs.aws.amazon.com/appsync/latest/devguide/designing-your-schema.html
In particular there is a section from the docs that I will paraphrase here.
Let's say you have a comment type
type Comment {
todoid: ID!
commentid: String!
content: String
}
In this case there are two id's and both are required, because this corresponds to a DynamoDB primary + sort key combination. You will map these fields to the keys in DynamoDB in your resolver mapping template.
The template could look like:
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key": {
"todoid" : { "S" : "${context.arguments.todoid}" },
"commentid" : { "S" : "${context.arguments.commentid}" }
},
"attributeValues" : {
"content" : { "S" : "${context.arguments.content}" }
}
}
In short if you are using a DynamoDB table that has two a hash + sort key, it is encouraged in AppSync to have them as required fields on the GraphQL type.