GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
Future of this repository: See this issue for details.
GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).
$ brew install --cask graphql-playgroundNOTE: only unsanitized user input to the functions in these packages is vulnerable to the recently reported XSS Reflection attack.
Impacted are any and all unsanitized user-defined input to: -
renderPlaygroundPage()-koaPlayground()-expressPlayground()-koaPlayground()-`lambdaPlayground()
If you used static values, such as
graphql-playground-electrondoes 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.
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.22graphql-playground-express ☔ safe @ 1.7.16graphql-playground-koa ☔ safe @ 1.6.15graphql-playground-hapi ☔ safe @ 1.6.13graphql-playground-lambda ☔ safe @ 1.7.17graphql-playground-electron has always been ☔ safe from XSS attacks! This is because configuration is statically defined it's webpack configgraphql-playground-react is safe because it does not use renderPlaygroundPage() anywhere, and thus is not susceptible to template string XSS reflection attacks.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
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:
See the following question for more additonal features.
The desktop app is the same as the web version but includes these additional features:
*.graphql files.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.
In the top right corner of the Playground window you can click on the settings icon. These are the settings currently available:
…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 hereconfig string - the JSON of a GraphQL Config. See an example heresettings ISettings - Editor settings in json format as described here…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 reloadedinterface 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 calledcreateApolloLink 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.
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:
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
yarn add graphql-playground-reactGraphQL 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.
<Playground /> componentThe 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,
)# 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-lambdaWe have a full example for each of the frameworks below:
Express: See packages/graphql-playground-middleware-express/examples/basic
Lambda (as serverless handler): See serverless-graphql-apollo or a quick example below.
yarn add graphql-playground-middleware-lambdahandler.js
…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: trueThere is an XSS Reflection Vulnerability when using these middlewares with unsanitized user input before
$ cd packages/graphql-playground-react
$ yarn
$ yarn startOpen localhost:3000/localDev.html?endpoint=https://api.graph.cool/simple/v1/swapi for local development!
This repository is managed by EasyCLA. Project participants must sign the free (GraphQL Specification Membership agreement before making a contribution. You only need to do this one time, and it can be signed by individual contributors or their employers.
To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.
You can find detailed information here. If you have issues, please email [email protected].
If your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also co
Consider deprecating and archiving this repo
Playground autoComplete or Type Box doesn't disappear.
Schema not updating on Windows/WSL2-Ubuntu
Is there a way to stop the playground from firing introspection query?
subscription could not connect to websocket endpoint wss://xxxxxx.com/graphql
State not saving correctly
graphql-playground-middleware-koa still using very old version of Playground
Load schema from file
GraphQL Playground
357<a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg" alt="CLA Signed" align="left" height="28" width="328" ></a><br/><br />The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: benjie / name: Benjie (bd6231ae75570137ecdfda440519a71633b92775)</li><li>:white_check_mark: login: Jason3S / name: Jason Dent (c4750138b6cbf787d3031a1cd3ee361336fba378)</li></ul><!-- Date Modified: 2024-06-10 12:20:12.140801 -->