GithubHelp home page GithubHelp logo

behappyf / graphql-voyager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from graphql-kit/graphql-voyager

0.0 2.0 0.0 9.43 MB

๐Ÿ›ฐ๏ธ Represent any GraphQL API as an interactive graph

Home Page: https://apis.guru/graphql-voyager/

License: MIT License

JavaScript 15.60% HTML 5.02% TypeScript 62.97% CSS 16.41%

graphql-voyager's Introduction

GraphQL Voyager

David David License: MIT

graphql-voyager logo

Represent any GraphQL API as an interactive graph. It's time to finally see the graph behind GraphQL. You can also explore number of public GraphQL APIs from our list.

With graphql-voyager you can visually explore your GraphQL API as an interactive graph. This is a great tool when designing or discussing your data model. It includes multiple example GraphQL schemas and also allows you to connect it to your own GraphQL endpoint. What are you waiting for, explore your API!

GraphQL Weekly #42

voyager demo

Features

  • Quick navigation on graph
  • Left panel which provides more detailed information about every type
  • "Skip Relay" option that simplifies graph by removing Relay wrapper classes
  • Ability to choose any type to be a root of the graph

Roadmap

Usage

GraphQL Voyager exports Voyager React component and helper init function. If used without module system it is exported as GraphQLVoyager global variable.

Properties

Voyager component accepts the following properties:

  • introspection [object or function: (query: string) => Promise] - the server introspection response. If function is provided GraphQL Voyager will pass introspection query as a first function parameter. Function should return Promise which resolves to introspection response object.
  • displayOptions
    • displayOptions.skipRelay [boolean, default true] - skip relay-related entities
    • displayOptions.rootType [string] - name of the type to be used as a root
    • displayOptions.sortByAlphabet [boolean, default false] - sort fields on graph by alphabet

init function

The signature of the init function:

(hostElement: HTMLElement, options: object) => void
  • hostElement - parent element
  • options - is the JS object with properties of Voyager component

Using pre-bundled version

You can get GraphQL Voyager bundle from the following places:

Important: for the latest two options make sure to copy voyager.worker.js to the same folder as voyager.min.js.

The HTML with minimal setup (see the full example)

<!DOCTYPE html>
<html>
  <head>
    <script src="//cdn.jsdelivr.net/react/15.4.2/react.min.js"></script>
    <script src="//cdn.jsdelivr.net/react/15.4.2/react-dom.min.js"></script>

    <link rel="stylesheet" href="./node_modules/graphql-voyager/dist/voyager.css" />
    <script src="./node_modules/graphql-voyager/dist/voyager.min.js"></script>
  </head>
  <body>
    <div id="voyager">Loading...</div>
    <script>
      function introspectionProvider(introspectionQuery) {
        // ... do a call to server using introspectionQuery provided
        // or just return pre-fetched introspection
      }

      // Render <Voyager />
      GraphQLVoyager.init(document.getElementById('voyager'), {
        introspection: introspectionProvider
      })
    </script>
  </body>
</html>

Using as a dependency

You can install lib using npm or yarn:

npm i --save graphql-voyager
yarn add graphql-voyager

And then use it:

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {Voyager} from 'graphql-voyager';
import fetch from 'isomorphic-fetch';

function introspectionProvider(query) {
  return fetch(window.location.origin + '/graphql', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({query: query}),
  }).then(response => response.json());
}

ReactDOM.render(<Voyager introspection={introspectionProvider} />, document.getElementById('voyager'));

Build for the web with webpack (example) or browserify

Important: make sure to copy voyager.worker.js from node_modules/graphql-voyager/dist to the same folder as your main bundle.

Middleware

Graphql Voyager has middleware for the next frameworks:

Express

Properties

Express middleware supports the following properties:

  • options
    • endpointUrl [string] - the GraphQL endpoint url.

Usage

import express from 'express';
import { express as middleware } from 'graphql-voyager/middleware';

const app = express();

app.use('/voyager', middleware({ endpointUrl: '/graphql' }));

app.listen(3000);

Hapi

Properties

Hapi middleware supports the following properties:

  • options
    • path [string] - the Voyager middleware url
    • voyagerOptions
      • endpointUrl [string] - the GraphQL endpoint url.

Usage

import hapi from 'hapi';
import { hapi as middleware } from 'graphql-voyager/middleware';

const server = new Hapi.Server();

server.connection({
  port: 3001
});

server.register({
  register: middleware,
  options: {
    path: '/voyager',
    endpointUrl: '/graphql'
  }
},() => server.start());

Koa

Properties

Koa middleware supports the following properties:

  • options
    • endpointUrl [string] - the GraphQL endpoint url.

Usage

import Koa from 'koa';
import KoaRouter from 'koa-router';
import { koa as middleware } from 'graphql-voyager/middleware';

const app = new Koa();
const router = new KoaRouter();

router.all('/voyager', voyagerMiddleware({
  endpointUrl: '/graphql'
}));

app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3001);

Credits

This tool is inspired by graphql-visualizer project.

graphql-voyager's People

Contributors

romanhotsiy avatar ivangoncharov avatar aschepis avatar kandros avatar steplov avatar timsuchanek avatar tuukka avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.