What is graphql-playground-html?
The graphql-playground-html npm package provides a way to embed GraphQL Playground, a powerful GraphQL IDE, into your web applications. It allows developers to interact with their GraphQL APIs through a user-friendly interface, making it easier to test queries, mutations, and subscriptions.
What are graphql-playground-html's main functionalities?
Embedding GraphQL Playground
This code sample demonstrates how to embed GraphQL Playground into an HTML page. It includes the necessary CSS and JavaScript files from a CDN and initializes the playground with a specified GraphQL endpoint.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>GraphQL Playground</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/static/css/index.css" />
<link rel="shortcut icon" href="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/favicon.png" />
<script src="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/static/js/middleware.js"></script>
</head>
<body>
<div id="root"></div>
<script>
window.addEventListener('load', function (event) {
GraphQLPlayground.init(document.getElementById('root'), { endpoint: '/graphql' })
})
</script>
</body>
</html>
Customizing GraphQL Playground
This code sample shows how to customize the GraphQL Playground by setting various options such as the editor theme and cursor shape. These settings can be adjusted to fit the developer's preferences.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>GraphQL Playground</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/static/css/index.css" />
<link rel="shortcut icon" href="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/favicon.png" />
<script src="https://cdn.jsdelivr.net/npm/graphql-playground-html@latest/build/static/js/middleware.js"></script>
</head>
<body>
<div id="root"></div>
<script>
window.addEventListener('load', function (event) {
GraphQLPlayground.init(document.getElementById('root'), {
endpoint: '/graphql',
settings: {
'editor.theme': 'dark',
'editor.cursorShape': 'line'
}
})
})
</script>
</body>
</html>
Other packages similar to graphql-playground-html
graphiql
GraphiQL is another popular GraphQL IDE that provides a similar interface for testing and interacting with GraphQL APIs. It is highly customizable and can be embedded into web applications. Compared to graphql-playground-html, GraphiQL is more lightweight but may lack some of the advanced features and polish of GraphQL Playground.
altair
Altair is a feature-rich GraphQL client that offers a wide range of functionalities, including query history, variable extraction, and more. It can be used as a standalone application or embedded into web applications. Altair provides a more extensive set of features compared to graphql-playground-html, making it suitable for more advanced use cases.
apollo-server
Apollo Server is a GraphQL server implementation that includes a built-in GraphQL Playground for testing queries and mutations. While it is primarily focused on serving GraphQL APIs, the included playground offers similar functionalities to graphql-playground-html. Apollo Server is a good choice if you need both a GraphQL server and an integrated playground.
graphql-playground-html
This package is being used by the GraphQL Playground middlewares.
For local development, you can yarn link
this package, then use yarn link graphql-playground-html
in the
middleware you want to develop.