Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

leonardoks16/astrid-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

astrid-client, a new alternative

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
  1. Installation
  2. Usage

Installation

Install npm package

  • npm
    npm install @leonardoks16/astrid-client@latest --save

Usage:

Create connection to GraphQL endpoint

// 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'
})

Make simple Query

// Define your query
const query = `{
    userList { _id }
  }`
  
// Make a simple query
astridQuery(query).then(data => {
  //console.log(data)
}).catch(error => console.error(error));

Query With Variables

astridQuery({
  query: queryWithVar,
  variables: {id, token}
}).then(data => {
  console.log(data)
}).catch(error => console.error(error));

Persisted queries

inputs: query, interval, callback function

// Make a persisted query, with a interval in ms

astridWatchQuery(query, 100, function(x) {
  //console.log(x)
}).catch(error => console.error(error))

Make simple Mutation

// 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))