- you are using Parse SDK (web or mobile) coupled with Parse Server
- you are using GraphQL
- you want to make sure your GraphQL queries are authenticated using Parse authentication
- [Recommended] you are also uing parse-graphql-server package
Install parse-graphql-client and make sure Parse JavaScript SDK is installed and configured
npm install --save parse-graphql-client parse
Create and configure and instance of GraphQLClient.
Note: GraphQLClient expects you to specify which Parse module to use. Example below uses a React Native version of Parse. If you are using GraphQLClient in a node environment, you would use require('parse/node')
, while a browser based app would call for require('parse')
import GraphQLClient from 'parse-graphql-client';
const client = new GraphQLClient(settings.graphqlURL, require('parse/react-native'));
client.query(`
{
todos {
id, text, isComplete
}
}
`).then(result => {
console.log(result.todos);
});
return client.mutate(`
{
newTodo: addTodo(text:"buy milk") {
id, text, isComplete
}
}
`).then(result => {
console.log(result.newTodo);
});
All resulting requests to your GraphQL server will arrive with Authorization
header set to current Parse session token. You can either take it from there, or use parse-graphql-server package to automate this even further.
Parse GraphQL client relies heavily on Lokka from Kadirahq.