0.1.18 • Published 7 years ago

cyclop-graph v0.1.18

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Cyclop

Cyclop is a GraphQL client. Cyclop use Content-Type : application/graphql only

Build Status

Installation

install with npm or yarn

npm install --save cyclop-graph
// or
yarn add cyclop-graph

install in a browser.

<script type="text/javascript" src="https://unpkg.com/cyclop-graph@0.1.8/dist/cyclop.js"></script>

Basic Usage

Query

module bundler style

import { CyclopConnection } from 'cyclop-graph'

const client = new CyclopConnection({
  url: "http://localhost:3000/graphql",
  headers: {
    Authorization: 'Bearer ' + token
  }
})

const documentExam = `query {
  getProducts {
    _id
    name
    price
    category
  }
}`

client.query(documentExam).then( response => {
  const {errors, data} = response
}).catch( (error) => {

});

Vanilla Style

<script type="text/javascript">

var client = new Cyclop.CyclopConnection({
  url: "http://localhost:3000/graphql",
  headers: {
    Authorization: 'Bearer ' + token
  }
});

var documentExam = `query {
  getProducts {
    _id
    name
    price
    category
  }
}`

client.query(documentExam).then( response => {
  console.log(response);
}).catch( (error) => {

});

</script>

Query With Variables

import { CyclopConnection } from 'cyclop-graph'

const client = new CyclopConnection({
  url: "http://localhost:3000/graphql",
  headers: {
    Authorization: 'Bearer ' + token
  }
})

const documentExam = `query {
  getProductByPrice(price : $price) {
    _id
    name
    price
    category
  }
}`

const variables = [{
  price: 2000,
}]

client.query(documentExam, variables).then( response => {
  const {errors, data} = response
}).catch( (error) => {

});

Mutation

import { CyclopConnection } from 'cyclop-graph'

const client = new CyclopConnection({
  url: "http://localhost:3000/graphql",
  headers: {
    Authorization: 'Bearer ' + token
  }
})

const addProductDoc = `mutation {
  addProduct(
    name: $name,
    price: $price,
    category: $category
  ) {
    _id
    name
    price
    category
  }
}`

const variables = [{
  name: "Ninetendo Switch",
  price: $299.99,
  category: ["game", "handheld"]
}]

client.mutate(addProductDoc, variables).then( response => {
  console.log(response)
}).catch( (error) => {

});

Multiple Documents

Variables must match documents.

import { CyclopConnection } from 'cyclop-graph'

const client = new CyclopConnection({
  url: "http://localhost:3000/graphql",
  headers: {
    Authorization: 'Bearer ' + token
  }
})

const addProductDoc = `mutation {
  addProduct(
    name: $name,
    price: $price,
    category: $category
  ) {
    _id
    name
    price
    category
  }
  getTagsByCategory(
    category: $category
  ) {
    _id
    name
    category
  }
}`

const variables = [{
  name: "Ninetendo Switch",
  price: $299.99,
  category: ["game", "handheld"]
}, {
  category: "game"
}]

client.mutate(addProductDoc, variables).then( response => {
  console.log(response)
}).catch( (error) => {

});

License

MIT

0.1.18

7 years ago

0.1.17

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.1

7 years ago