Skip to content

Chuan-Zh/graphql-voyager

 
 

Repository files navigation

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.

Credits

This tool is inspired by graphql-visualizer project.

About

🛰️ Represent any GraphQL API as an interactive graph

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 62.3%
  • CSS 17.4%
  • JavaScript 15.0%
  • HTML 5.3%