AWS AppSync provides a GraphQL service for the LambdaMessenger project. With AppSync, realtime message updates can be retrieved from clients using GraphQL Subscriptions.
-
In the AWS Admin console, navigate to the AppSync service and create a new API. Select "Author from Scratch" to get started.
-
Under settings, set the authorization type as "OpenID Connect". The OpenID connect provider should be set using the provider name for your Firebase project.
-
Create your schema. Copy the
config/aws-appsync-schema.graphql
file into the schema section of the AppSync console. -
Configure your data sources. Create the following data sources (one per each Lambda Function).
- getConversation
- getConversationHistory
- initiateConversation
- lookupUserByEmail
- lookupUserByPhoneNumber
- postMessage
- registerUserWithEmail
- registerUserWithPhoneNumber
- updateUser
DataSource creation should look like this:
-
Configure your resolvers. You only need to set resolvers for your Queries and Mutations. Copy and paste the JSON below for each Query and Mutation:
Request mapping templates:
{ "version" : "2017-02-28", "operation": "Invoke", "payload": { "user" : { "userId": $utils.toJson($context.identity.claims.sub), "email" : $utils.toJson($context.identity.claims.email), "phoneNumber" : $utils.toJson($context.identity.claims.phone_number), "displayName" : $utils.toJson($context.identity.claims.name), }, "arguments": $utils.toJson($context.args) } }
Response mapping templates:
$util.toJson($context.result)