graphql-jay

0.1.0 • Public • Published

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

SWAPI

License

MIT © Mateus Maso

Package Sidebar

Install

npm i graphql-jay

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mateusmaso