graphql-playground-react

WebJar for graphql-playground-react

License

License

MIT
Categories

Categories

React User Interface Web Frameworks
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

graphql-playground-react
Last Version

Last Version

1.7.27
Release Date

Release Date

Type

Type

jar
Description

Description

graphql-playground-react
WebJar for graphql-playground-react
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/graphql/graphql-playground

Download graphql-playground-react

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/graphql-playground-react/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>graphql-playground-react</artifactId>
    <version>1.7.27</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/graphql-playground-react/
implementation 'org.webjars.npm:graphql-playground-react:1.7.27'
// https://jarcasting.com/artifacts/org.webjars.npm/graphql-playground-react/
implementation ("org.webjars.npm:graphql-playground-react:1.7.27")
'org.webjars.npm:graphql-playground-react:jar:1.7.27'
<dependency org="org.webjars.npm" name="graphql-playground-react" rev="1.7.27">
  <artifact name="graphql-playground-react" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='graphql-playground-react', version='1.7.27')
)
libraryDependencies += "org.webjars.npm" % "graphql-playground-react" % "1.7.27"
[org.webjars.npm/graphql-playground-react "1.7.27"]

Dependencies

compile (52)

Group / Artifact Type Version
org.webjars.npm : query-string jar [5,6)
org.webjars.npm : graphql jar [15.3.0,16)
org.webjars.npm : copy-to-clipboard jar [3.0.8,4)
org.webjars.npm : react-copy-to-clipboard jar [5.0.1,6)
org.webjars.npm : styled-components jar [4.0.0,5)
org.webjars.npm : lodash.debounce jar [4.0.8,5)
org.webjars.npm : codemirror jar [5.58.1,6)
org.webjars.npm : isomorphic-fetch jar [2.2.1,3)
org.webjars.npm : zen-observable jar [0.7.1,0.8)
org.webjars.npm : redux-localstorage-filter jar [0.1.1,0.2)
org.webjars.npm : react-codemirror jar [1.0.0,2)
org.webjars.npm : seamless-immutable jar [7.0.1,8)
org.webjars.npm : react-input-autosize jar [2.2.1,3)
org.webjars.npm : react-addons-shallow-compare jar [15.6.2,16)
org.webjars.npm : redux-localstorage jar [1.0.0-rc5,2)
org.webjars.npm : react-dom jar [16.13.1,17)
org.webjars.npm : apollo-link jar [1.2.13,2)
org.webjars.npm : react-display-name jar [0.2.3,0.3)
org.webjars.npm : codemirror-graphql jar [0.12.3,0.13)
org.webjars.npm : marked jar [0.8.2,0.9)
org.webjars.npm : immutable jar [4.0.0-rc.9,5)
org.webjars.npm : prettier jar [2.0.2]
org.webjars.npm : utility-types jar [1.0.0,2)
org.webjars.npm : lodash jar [4.17.11,5)
org.webjars.npm : react-transition-group jar [2.2.1,3)
org.webjars.npm : react-modal jar [3.1.11,4)
org.webjars.npm : redux-saga jar [1.1.3,2)
org.webjars.npm : react-router-dom jar [4.2.2,5)
org.webjars.npm : json-stable-stringify jar [1.0.1,2)
org.webjars.npm : cuid jar [1.3.8,2)
org.webjars.npm : redux jar [4.0.5,5)
org.webjars.npm : redux-localstorage-debounce jar [0.1.0,0.2)
org.webjars.npm : react-helmet jar [5.2.0,6)
org.webjars.npm : react-virtualized jar [9.12.0,10)
org.webjars.npm : redux-immutable jar [4.0.0,5)
org.webjars.npm : apollo-link-ws jar [1.0.19,2)
org.webjars.npm : react jar [16.13.1]
org.webjars.npm : types__lru-cache jar [4.1.1,5)
org.webjars.npm : graphiql jar [0.17.5,0.18)
org.webjars.npm : react-redux jar [7.2.0,8)
org.webjars.npm : calculate-size jar [1.1.1,2)
org.webjars.npm : js-yaml jar [3.10.0,4)
org.webjars.npm : subscriptions-transport-ws jar [0.9.5,0.10)
org.webjars.npm : redux-actions jar [2.6.5,3)
org.webjars.npm : keycode jar [2.1.9,3)
org.webjars.npm : prop-types jar [15.7.2,16)
org.webjars.npm : reselect jar [4.0.0,5)
org.webjars.npm : cryptiles jar [4.1.2]
org.webjars.npm : markdown-it jar [8.4.1,9)
org.webjars.npm : apollo-link-http jar [1.5.16,2)
org.webjars.npm : react-sortable-hoc jar [0.8.3,0.9)
org.webjars.npm : webpack-bundle-analyzer jar [3.3.2,4)

Project Modules

There are no modules declared in this project.

Note: The primary maintainer @acao is on hiatus until December 2020

SECURITY WARNING: both graphql-playground-html and all four (4) of it's middleware dependents until [email protected] were subject to an XSS Reflection attack vulnerability only to unsanitized user input strings to the functions therein. This was resolved in graphql-playground-html@^1.6.22. More Information

npm version prisma-labs

Future of this repository: see the announcement issue for details.


GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).

Installation

$ brew cask install graphql-playground

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

Security Details

NOTE: only unsanitized user input to the functions in these packages is vulnerable to the recently reported XSS Reflection attack.

Impact

Impacted are any and all unsanitized user-defined input to: -renderPlaygroundPage() -koaPlayground() -expressPlayground() -koaPlayground() -`lambdaPlayground()

If you used static values, such as graphql-playground-electron does in it's webpack config, as well as the most common middleware implementations out there, they were not vulnerable to the attack.

The only reason this vulnerability exists is because we are using template strings in renderPlaygroundPage() with potentially unsanitized user defined variables. This allows an attacker to inject html and javascript into the page.

Common examples may be user-defined path parameters, query string, unsanitized UI provided values in database, etc., that are used to build template strings or passed directly to a renderPlaygroundPage() or the matching middleware function equivalent listed above.

Impacted Packages

All versions of these packages are impacted until the ones specified below, which are now safe for user defined input:

  • graphql-playground-html: โ˜” safe @ 1.6.22
  • graphql-playground-express โ˜” safe @ 1.7.16
  • graphql-playground-koa โ˜” safe @ 1.6.15
  • graphql-playground-hapi โ˜” safe @ 1.6.13
  • graphql-playground-lambda โ˜” safe @ 1.7.17
  • graphql-playground-electron has always been โ˜” safe from XSS attacks! This is because configuration is statically defined it's webpack config
  • graphql-playground-react is safe because it does not use renderPlaygroundPage() anywhere, and thus is not susceptible to template string XSS reflection attacks.

More Information

See the security docs for more details on how your implementation might be impacted by this vulnerability. It contains safe examples, unsafe examples, workarounds, and more details.

We've also provided 'an example of the xss using the express middleware

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:

  • Partial support for graphql-config enabling features like multi-environment setups (no support for sending HTTP headers).
  • 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.

Settings

In the top right corner of the Playground window you can click on the settings icon. These are the settings currently available:

{
  'editor.cursorShape': 'line', // possible values: 'line', 'block', 'underline'
  'editor.fontFamily': `'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace`,
  'editor.fontSize': 14,
  'editor.reuseHeaders': true, // new tab reuses headers from last tab
  'editor.theme': 'dark', // possible values: 'dark', 'light'
  'general.betaUpdates': false,
  'prettier.printWidth': 80,
  'prettier.tabWidth': 2,
  'prettier.useTabs': false,
  'request.credentials': 'omit', // possible values: 'omit', 'include', 'same-origin'
  'schema.polling.enable': true, // enables automatic schema polling
  'schema.polling.endpointFilter': '*localhost*', // endpoint filter for schema polling
  'schema.polling.interval': 2000, // schema polling interval in ms
  'schema.disableComments': boolean,
  'tracing.hideTracingResponse': true,
  'tracing.tracingSupported': true, // set false to remove x-apollo-tracing header from Schema fetch requests
}

Usage

Properties

The React component <Playground /> and all middlewares expose the following options:

  • props (Middlewares & React Component)
    • endpoint string - the GraphQL endpoint url.
    • subscriptionEndpoint string - the GraphQL subscriptions endpoint url.
    • workspaceName string - in case you provide a GraphQL Config, you can name your workspace here
    • config string - the JSON of a GraphQL Config. See an example here
    • settings ISettings - Editor settings in json format as described here
interface ISettings {
  'editor.cursorShape': 'line' | 'block' | 'underline'
  'editor.fontFamily': string
  'editor.fontSize': number
  'editor.reuseHeaders': boolean
  'editor.theme': 'dark' | 'light'
  'general.betaUpdates': boolean
  'prettier.printWidth': number
  'prettier.tabWidth': number
  'prettier.useTabs': boolean
  'request.credentials': 'omit' | 'include' | 'same-origin'
  'request.globalHeaders': { [key: string]: string }
  'schema.polling.enable': boolean
  'schema.polling.endpointFilter': string
  'schema.polling.interval': number
  'schema.disableComments': boolean
  'tracing.hideTracingResponse': boolean
  'tracing.tracingSupported': boolean
}
  • schema IntrospectionResult - The result of an introspection query (an object of this form: {__schema: {...}}) The playground automatically fetches the schema from the endpoint. This is only needed when you want to override the schema.
  • tabs Tab[] - An array of tabs to inject. Note: When using this feature, tabs will be resetted each time the page is reloaded
interface Tab {
  endpoint: string
  query: string
  name?: string
  variables?: string
  responses?: string[]
  headers?: { [key: string]: string }
}

In addition to this, the React app provides some more properties:

  • props (React Component)
  • createApolloLink [(session: Session, subscriptionEndpoint?: string) => ApolloLink] - this is the equivalent to the fetcher of GraphiQL. For each query that is being executed, this function will be called

createApolloLink is only available in the React Component and not the middlewares, because the content must be serializable as it is being printed into a HTML template.

As HTML Page

If you simply want to render the Playground HTML on your own, for example when implementing a GraphQL Server, there are 2 options for you:

  1. The bare minimum HTML needed to render the Playground
  2. The Playground HTML with full loading animation

Note: In case you do not want to serve assets from a CDN (like jsDelivr) and instead use a local copy, you will need to install graphql-playground-react from npm, and then replace all instances of //cdn.jsdelivr.net/npm with ./node_modules. An example can be found here

As React Component

Install

yarn add graphql-playground-react

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 React component.

  1. Open Sans and Source Code Pro fonts
  2. 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 { Provider } from 'react-redux'
import { Playground, store } from 'graphql-playground-react'

ReactDOM.render(
  <Provider store={store}>
    <Playground endpoint='https://api.graph.cool/simple/v1/swapi' />
  </Provider>,
  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

Security Issue

There is an XSS Reflection Vulnerability when using these middlewares with unsanitized user input before

Development

$ cd packages/graphql-playground-react
$ yarn
$ yarn start

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

Custom Theme

From [email protected] on you can provide a codeTheme property to the React Component to customize your color theme. These are the available options:

export interface EditorColours {
  property: string
  comment: string
  punctuation: string
  keyword: string
  def: string
  qualifier: string
  attribute: string
  number: string
  string: string
  builtin: string
  string2: string
  variable: string
  meta: string
  atom: string
  ws: string
  selection: string
  cursorColor: string
  editorBackground: string
  resultBackground: string
  leftDrawerBackground: string
  rightDrawerBackground: string
}

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 Discord

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

Prisma

org.webjars.npm

GraphQL

Versions

Version
1.7.27
1.7.26