This repository demonstrates how to integrate AWS AppSync with Cognito for authentication, and use client libraries such as Apollo and Amplify for querying the GraphQL endpoints.
This project contains examples of how to interact with AWS AppSync using different approaches:
- Using Amplify by itself.
- Using Apollo with the Cognito ID.
- Using Amplify for querying AppSync, but with Cognito ID for authentication.
Ensure you have Node.js installed on your machine.
-
Clone this repository:
git clone https://github.com/razorRun/appsync-cognito-apollo-amplify-test cd appsync-cognito-apollo-amplify-test
-
Install dependencies:
npm install
There are three scripts you can run, each representing one of the three approaches:
-
Using Amplify by itself:
npm run start-amplify
-
Using Apollo with the Cognito ID:
npm run start-apollo
-
Using Amplify for querying AppSync, but with Cognito ID for authentication:
npm run start-ca
- Ensure you've set up your AWS AppSync and Cognito correctly for these scripts to function.
- Never hardcode sensitive credentials directly in your scripts. It's recommended to use environment variables or AWS Secrets Manager.
- These scripts are meant for demonstration and might need adjustments based on your actual AppSync and Cognito configurations.
- @apollo/client: For making GraphQL requests using Apollo Client.
- @aws-amplify/core and @aws-amplify/ui-react: Core Amplify libraries for configuration and UI components.
- amazon-cognito-identity-js: Provides Cognito Identity functionality.
- aws-amplify: Complete AWS Amplify library.
- graphql: JavaScript reference implementation for GraphQL.
- Roshan Milinda
- MIT