Skip to content

Instantly share code, notes, and snippets.

@koingdev
Created July 22, 2019 09:36
Show Gist options
  • Save koingdev/cfe4224b5cd414135156e92b0f8e7a5f to your computer and use it in GitHub Desktop.
Save koingdev/cfe4224b5cd414135156e92b0f8e7a5f to your computer and use it in GitHub Desktop.
Query items with PK and response in an order based on range key
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
"expression" : "author = :author",
"expressionValues" : {
":author" : $util.dynamodb.toDynamoDBJson($ctx.args.author)
}
},
## false -> DESC ORDER
"scanIndexForward" : false
}
@ohsik
Copy link

ohsik commented Aug 2, 2019

I'm still not familiar with resolvers. Is this something I have to update on AWS console?
AppSync > Schema > Resolvers on the right side?

How do I use this??

@koingdev
Copy link
Author

koingdev commented Aug 2, 2019

I'm still not familiar with resolvers. Is this something I have to update on AWS console?
AppSync > Schema > Resolvers on the right side?

How do I use this??

If you are using Amplify, you can create your custom query in schema.graphql file and define customer resolver for that query in folder resolvers

@koingdev
Copy link
Author

koingdev commented Aug 2, 2019

I just created a small document showing how to make AWS Amplify support custom field (Query/Mutation).
Check this out: https://gist.github.com/koingdev/16084d28b64575e488bb216109ec2554
This will be helpful for u.

@ohsik
Copy link

ohsik commented Aug 6, 2019

@koingdev
Thank you for the comment. I'm still implementing the new schema from you but got a question about this since it's kind of related to schema structure.

Since I'm changing it to your schema, I will be using getUser to get that user's journal list. However, how do I query 30 latest journals and load 30 more in a chronological order? is this resolver will do that? or should I add @key directive into Journal?

@ohsik
Copy link

ohsik commented Aug 8, 2019

@koingdev
One more thing I'm curious about for querying. I have a page that shows all PUBLIC journals from all the users on the site by date. I want to query latest 30 PUBLIC journals from everyone on the site and next 30 more by chronological order.

I'm not sure what is the best way to do this.

  1. Add @key to schema.graphql? something like Journal @model @key(fields: ["privacy", "createdAt"])?
  2. Use resolver? (still trying to understand how this works lol)

@koingdev
Copy link
Author

koingdev commented Aug 8, 2019

@ohsik

  1. Defining a key is a way to enable your data access pattern.
  2. Using custom resolver is a way to control over Amplify. We know that Amplify has GraphQL Transform which will automatically create DynamoDB table and some default CRUD queries and mutations. But sometimes those autogenerated queries and mutations doesn't match our need or requirement. This is when custom field and resolver come in.

@ohsik
Copy link

ohsik commented Aug 12, 2019

@koingdev Thank you! didn't know u replied here till today haha.

So as long as I have the scalable database structure, I can user resolvers for custom queries and mutations.

I ended up modifying the schema file little bit the way I think it makes sense here(https://gist.github.com/ohsik/1506c0530a6744cff158f8af408be731) and moving on to building the app again.

Thank you for the help again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment