Skip to content

mateusmaso/graphql-jay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-jay Build Status

This is a GraphQL schema generator for composing Web APIs. It embraces the idea of querying data from multiple services (GraphQL API, REST API, JSON-RPC API, etc) within a single and unified GraphQL schema using the least expensive route available. By automating the data fetching process, it allows teams to constantly reason, experiment and perform changes on the API specification without versioning in order to solve data-flow problems.

Install

$ npm install --save graphql-jay

Usage

import {graphql} from "graphql"
import {composeSchema} from "graphql-jay"
import {v1, rpc, graph} from "./services"

composeSchema(v1, rpc, graph).then((schema) => {
  graphql(schema, `{
    user(id: 1) {
      id
      name
      posts {
        id
        creator {
          id
          email
          image {
            small
          }
        }
      }
    }
  }`).then((response) => {
    var {user} = response.data
  })
})

Defining Services

GraphQL API

import fetch from "isomorphic-fetch"
import {introspectionQuery} from "graphql"

var url = "http://myservice.com/graphql"

export default function service() {
  return fetch(url, {
    body: JSON.stringify({
      query: introspectionQuery,
    }),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    method: 'POST'
  }).then((response) => {
    return response.json()
  }).then((response) => {
    var wrapper = {
      User: {
        "imageUrl": "image.small"
      }
    }

    return {
      url,
      metadata: response.data,
      wrapper
    }
  })
}

REST API

Examples

License

MIT © Mateus Maso