Package that makes easier the graphql requests to appsync when the authentication method is Cognito user pools
After installing the package, import the query manager as any package other package like this:
const acq = require('appsync-cognito-query');
Then we need to init the query manager and set the endpoint.
const manager = acq.init(YOUR_APPSYNC_ENDPOINT);
Then we can access the main functions of the manager. For a mutation query for example first we need to authenticate and then we can use graphql with the query method:
await manager.authenticateUser(YOUR_USER_POOL_ID, YOUR_CLIENT_ID, COGNITO_USER_USERNAME, COGNITO_USER_PASSWORD);
const mutation = `
mutation CreateMessage {
createMessage(input: {
messageChatId:"5523456789",
id: "12345",
content:"Message content",
createdAt: "2019-07-01T20:26:57.761Z",
type: "TEXT"
}) {
id
content
type
createdAt
}
}`;
await manager.query(mutation);
This NPM package is installed such as any other one with the next command:
npm install appsync-cognito-query
npm run test
- Node-fetch - Fetch
- amazon-cognito-identity-js - Dependency for the cognito auth
- graphql-request - Request Client
I encourage and support the open source code so I will be very happy to receive contributions.
- David Aguilar - Code - gdaguilarc
See also the list of contributors who participated in this project.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details