A preprocessor for mdbook to add GraphQL playgrounds.
https://aschaeffer.github.io/mdbook-preprocessor-graphql-playground/
mdbook-preprocessor-graphql-playground
shell
cargo install mdbook-preprocessor-graphql-playground
Add to book.toml
:
```toml
[preprocessor.graphql-playground]
command = "mdbook-graphql-playground"
renderer = ["html"]
[output]
[output.html] additional-js = ["graphql-playground-react-middleware.js", "graphql-playground.js"] additional-css = ["graphql-playground.css"] ```
shell
cp assets/graphql-playground.css <book_dir>
cp assets/graphql-playground.js <book_dir>
cp assets/graphql-playground-react-middleware.js <book_dir>
cp assets/images/* <book_dir>/src/images/
shell
mkdir -p <book_dir>/queries/swapi
nano <book_dir>/queries/swapi/all-planets.query.graphql
shell
mkdir <book_dir>/configs
nano <book_dir>/configs/swapi.json
{{ graphql_playground(config="/configs/swapi.json") }}
graphql
query AllPlanetsQuery {
allPlanets {
planets {
name
diameter
}
}
}
json
{
"title": "The Star Wars API",
"description": "Explore the star wars API using mdbook-preprocessor-graphql-playground",
"endpoint": "https://swapi-graphql.netlify.app/.netlify/functions/index",
"tabs": [
{
"name": "All Planets",
"url": "/queries/swapi/all-planets.query.graphql"
}
]
}
graphql_playground
functionconfig
parameter
{{ graphql_playground(config="/configs/swapi.json") }}
A full example can be found in this repository