Giter Club home page Giter Club logo

mdbook-preprocessor-graphql-playground's Introduction

mdbook-preprocessor-graphql-playground

Crate downloads

A preprocessor for mdbook to add GraphQL playgrounds.

preview

Demo

https://aschaeffer.github.io/mdbook-preprocessor-graphql-playground/

Usage

  1. Install mdbook-preprocessor-graphql-playground
    cargo install mdbook-preprocessor-graphql-playground
  2. Add to book.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"]
  3. Copy assets into the book root directory:
    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/
  4. Create a query file
    mkdir -p <book_dir>/queries/swapi
    nano <book_dir>/queries/swapi/all-planets.query.graphql
  5. Create a config file
    mkdir <book_dir>/configs
    nano <book_dir>/configs/swapi.json
  6. Embed the GraphQL Playground in your markdown files
    {{ graphql_playground(config="/configs/swapi.json") }}
    

Query files

  • You can have multiple queries
query AllPlanetsQuery {
  allPlanets {
    planets {
      name
      diameter
    }
  }
}

Config files

  • You can have multiple config files
  • You can have multiple tabs, each refers to a query
{
  "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"
    }
  ]
}

Use a config in the book

  1. Embed with the graphql_playground function
  2. Specify the location of the config file with the config parameter
{{ graphql_playground(config="/configs/swapi.json") }}

Example

A full example can be found in this repository

mdbook-preprocessor-graphql-playground's People

Contributors

aschaeffer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.