A REAL Platform Agnostic GraphQL Client, made with javascript and love. Deal with GraphQL in a blazing fast way. Unpacked Size: 7.02 kB
Table of Contents
Install npm package
- npm
npm install @leonardoks16/astrid-client@latest --save
// Import package, you can import only what will be used, of course. Only createClient is required
import { createClient, astridQuery, astridWatchQuery, astridMutation } from '../astrid-client';
// Create connection to graphql endpoint
createClient({
base_url: 'http://localhost:4000'
})
// Define your query
const query = `{
userList { _id }
}`
// Make a simple query
astridQuery(query).then(data => {
//console.log(data)
}).catch(error => console.error(error));
astridQuery({
query: queryWithVar,
variables: {id, token}
}).then(data => {
console.log(data)
}).catch(error => console.error(error));
// Make a persisted query, with a interval in ms
astridWatchQuery(query, 100, function(x) {
//console.log(x)
}).catch(error => console.error(error))
// Define your mutation
const mutation = `
mutation login($login: String! $password: String! ){
login(login: $login, password: $password ){
token, id
}
}
`
// Define your mutation variables if will be needed
const login = '[email protected]'
const password = '123456767'
// you can do this if you want too
const {login, password} = payload
// or just pass the variables as json object too
// Make a mutation
astridMutation({
mutation: mutation,
variables: {
login,
password,
}
}).then(data => {
//console.log(data)
}).catch(error => console.error(error))