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 untilgraphql-playground-html@1.6.22
were subject to an XSS Reflection attack vulnerability only to unsanitized user input strings to the functions therein. This was resolved ingraphql-playground-html@^1.6.22
. More Information CVE-2020-4038
Future of this repository: see the announcement issue for details.
GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).
$ brew install --cask graphql-playground
NOTE: 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-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.
All versions of these packages are impacted until the ones specified below, which are now safe for user defined input:
graphql-playground-html
:
1.6.22
graphql-playground-express
1.7.16
graphql-playground-koa
1.6.15
graphql-playground-hapi
1.6.13
graphql-playground-lambda
1.7.17
graphql-playground-electron
has always been
graphql-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:
{
'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
}
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 hereinterface 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 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-react
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.
<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-lambda
We 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-lambda
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
There is an XSS Reflection Vulnerability when using these middlewares with unsanitized user input before
$ cd packages/graphql-playground-react
$ yarn
$ yarn start
Openlocalhost: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 operations@graphql.org.
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 consider membership in the GraphQL Foundation.
From graphql-playground-react@1.7.0
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
}
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.
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 JSDelivergraphql-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 ReactJSJoin our Discord Server if you run into issues or have questions. We love talking to you!
最近在了解GraphQL,根据https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/里面的例子搭建了一个demo,结果在使用GraphQL playground来查看GraphQL demo结果的时候,报错: Failed to fetch. Please check your connection F12查
lighthouse by Oliver Nybroe 由Oliver Nybroe Laravel中的GraphQL做得正确:如何在一个简单的博客中设置Lighthouse (GraphQL in Laravel done right: how to set up Lighthouse in a simple blog) Recently a new package has revolution
In this lesson we'll use a simple GraphQL IDL schema to deploy and explore a fully functional GraphQL service in minutes with graphql-up. Install: npm i -g graphql-up -g Create schema: type Person
为了获取服务端GraphQl接口的数据,客户端需要使用apollo这个插件,三大前端框架均可以将apollo集成,下面以vue为例来说明在客户端如何集成vue-apollo这个插件。 1. 参考文档 Vue-apollo项目地址:https://github.com/Akryum/vue-apollo Vue-apollo官方文档:https://vue-apollo.netlify.com/ 2
快速开始 GraphQL 是一种用于 API 的查询语言。这是 GraphQL 和 REST 之间一个很好的比较 (译者注: GraphQL 替代 REST 是必然趋势)。在这组文章中, 我们不会解释什幺是 GraphQL, 而是演示如何使用 @nestjs/GraphQL 模块。 GraphQLModule 只不过是 Apollo 服务器的包装器。我们没有造轮子, 而是提供一个现成的模块, 这让
GraphQL 既是一种用于 API 的查询语言也是一个满足你数据查询的运行时。 GraphQL 对你的 API 中的数据提供了一套易于理解的完整描述,使得客户端能够准确地获得它需要的数据,而且没有任何冗余,也让 API 更容易地随着时间推移而演进,还能用于构建强大的开发者工具。 向你的 API 发出一个 GraphQL 请求就能准确获得你想要的数据,不多不少。 GraphQL 查询总是返回可预测
Graphql editor 是一款 Graphql 的可视化编辑器和 IDE,帮助用户更容易理解 GraphQL 模式,通过使用可视化块系统创建模式。GraphQL Editor 将把它们转化为代码。通过 GraphQL Editor,用户可以在不写任何代码的情况下创建可视化的图表,或者以一种很好的方式呈现其模式。 GraphQL View Code Editor View Hierarchy View
GraphQL CLI Help us to improve new GraphQL CLI. Check out the new structure and commands below!Feel free to contact us in Discord channel. We would love to hear your feedback. Features Helpful command
Fullstack GraphQL Simple Demo Application API built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux. Written in ES6 using Babel
Hasura GraphQL Engine Hasura is an open source product that accelerates API development by 10x by giving you GraphQL or REST APIs with built in authorization on your data, instantly. Read more at hasu