Git Product home page Git Product logo

graphql-playground's Introduction

GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).
You can download the desktop app or use the web version at graphqlbin.com: Demo

Features

  • โœจ Context-aware autocompletion & error highlighting
  • ๐Ÿ“š Interactive, multi-column docs (keyboard support)
  • โšก๏ธ Supports real-time GraphQL Subscriptions
  • โš™ GraphQL Config support with multiple Projects & Endpoints
  • ๐Ÿšฅ Apollo Tracing support

FAQ

How is this different from GraphiQL?

GraphQL Playground uses components of GraphiQL under the hood but is meant as a more powerful GraphQL IDE enabling better (local) development workflows. Compared to GraphiQL, the GraphQL Playground ships with the following additional features:

  • Interactive, multi-column schema documentation
  • Automatic schema reloading
  • Support for GraphQL Subscriptions
  • Query history
  • Configuration of HTTP headers
  • Tabs

See the following question for more additonal features.

What's the difference between the desktop app and the web version?

The desktop app is the same as the web version but includes these additional features:

  • Support for graphql-config enabling features like multi-environment setups.
  • Double click on *.graphql files.

How does GraphQL Bin work?

You can easily share your Playgrounds with others by clicking on the "Share" button and sharing the generated link. You can think about GraphQL Bin like Pastebin for your GraphQL queries including the context (endpoint, HTTP headers, open tabs etc).

You can also find the announcement blog post here.

Usage

Properties

All interfaces, the React component <Playground /> and all middlewares expose the same set of options:

  • properties
    • endpoint [string] - the GraphQL endpoint url.
    • subscriptionEndpoint [string] - the GraphQL subscriptions endpoint url.
    • setTitle [boolean] - reflect the current endpoint in the page title

As React Component

Install

yarn add graphql-playground

Use

GraphQL Playground provides a React component responsible for rendering the UI and Session management. There are 3 dependencies needed in order to run the graphql-playground React component.

  1. Open Sans and Source Code Pro fonts
  2. Including graphql-playground/playground.css
  3. Rendering the <Playground /> component

The GraphQL Playground requires React 16.

Including Fonts (1.)

<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700" rel="stylesheet">

Including stylesheet and the component (2., 3.)

import React from 'react'
import ReactDOM from 'react-dom'
import Playground from 'graphql-playground'
import 'graphql-playground/playground.css'

ReactDOM.render(<Playground endpoint="https://api.graph.cool/simple/v1/swapi" />, document.body)

As Server Middleware

Install

# Pick the one that matches your server framework
yarn add graphql-playground-middleware-express  # for Express or Connect
yarn add graphql-playground-middleware-hapi
yarn add graphql-playground-middleware-koa
yarn add graphql-playground-middleware-lambda

Usage with example

We have a full example for each of the frameworks below:

As serverless handler

Install

yarn add graphql-playground-middleware-lambda

Usage

handler.js

import lambdaPlayground from 'graphql-playground-middleware-lambda'
// or using require()
// const lambdaPlayground = require('graphql-playground-middleware-lambda').default

exports.graphqlHandler = function graphqlHandler(event, context, callback) {
  function callbackFilter(error, output) {
    // eslint-disable-next-line no-param-reassign
    output.headers['Access-Control-Allow-Origin'] = '*';
    callback(error, output);
  }

  const handler = graphqlLambda({ schema: myGraphQLSchema });
  return handler(event, context, callbackFilter);
};

exports.playgroundHandler = lambdaPlayground({
  endpoint: '/dev/graphql',
});

serverless.yml

functions:
  graphql:
    handler: handler.graphqlHandler
    events:
    - http:
        path: graphql
        method: post
        cors: true
  playground:
    handler: handler.playgroundHandler
    events:
    - http:
        path: playground
        method: get
        cors: true

Development npm version CircleCI

This is a mono-repo setup containing packages for the graphql-playground-react and graphql-playground-electron.

# installs all dependencies for all packages
$ yarn
$ cd packages/graphql-playground-react
$ yarn start

Open localhost:3000/middleware.html?endpoint=https://api.graph.cool/simple/v1/swapi for local development!

Versions

This is repository is a "mono repo" and contains multiple packages using Yarn workspaces. Please be aware that versions are not synchronised between packages. The versions of the release page refer to the electron app.

Packages

In the folder packages you'll find the following packages:

  • graphql-playground-electron: Cross-platform electron app which uses graphql-playground-react
  • graphql-playground-html: Simple HTML page rendering a version of graphql-playground-react hosted on JSDeliver
  • graphql-playground-middleware-express: Express middleware using graphql-playground-html
  • graphql-playground-middleware-hapi: Hapi middleware using graphql-playground-html
  • graphql-playground-middleware-koa: Koa middleware using graphql-playground-html
  • graphql-playground-middleware-lambda: AWS Lambda middleware using graphql-playground-html
  • graphql-playground-react: Core of GraphQL Playground built with ReactJS

Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!

graphql-playground's People

Contributors

albinekb avatar craig-day avatar devanb avatar fabien0102 avatar huv1k avatar jeroenvisser101 avatar kbrandwijk avatar marktani avatar mertindervish avatar morajabi avatar mtsewrs avatar newswim avatar nikolasburk avatar overra avatar renovate-bot avatar renovate[bot] avatar schickling avatar slashmo avatar timsuchanek avatar vincenzo avatar vovacodes avatar xavxyz avatar xoredg avatar

Watchers

 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.