JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2618
  • Score
    100M100P100Q115806F
  • License MIT

Docusaurus plugin generating Markdown documentation from a GraphQL schema.

Package Exports

  • docusaurus-graphql-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (docusaurus-graphql-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

docusaurus-graphql-plugin

Docusaurus plugin generating Markdown documentation from a GraphQL schema.

Motivation

The goal of this plugin is to generate a documentation that is pleasant to browse, based on a GraphQL schema. The templates it generates is heavily inspired by GitHub's documentation, which I enjoy browsing.

Usage

Installation

  1. In an existing Docusaurus project, install the plugin:
yarn add docusaurus-graphql-plugin
  1. Add the plugin to your docusaurus.config.js file:
module.exports = {
  plugins: [
    [
      "docusaurus-graphql-plugin",
      {
        // can be a path, a glob or an URL
        schema: "schema.graphql",
      },
    ],
  ],
};
  1. Start the application:
yarn start
  1. The plugin will generate Markdown files in the docs/api folder. So you can now add these files to your sidebars.js:
modules.exports = {
  docs: {
    API: [
      "api/queries",
      "api/mutations",
      "api/objects",
      "api/interfaces",
      "api/enums",
      "api/unions",
      "api/inputObjects",
      "api/scalars",
    ],
  },
};

Options

schema

Can be a path, a glob or an URL used to load your GraphQL schema.

routeBasePath

Defaults: /docs/api/

This option is used for two things:

  1. To generate reference links, such as the return type of a query being linked to its corresponding object.
  2. To generate the path where the files will be written to disk.

So if you want the API docs to be served over /docs/api-reference/ instead of /docs/api/, you can change this option to /docs/api-reference/. Note that you can also have more levels to the path, e.g /docs/reference/api/.

You must change this option if you are using the docs plugin's routeBasePath. For example, if you opted for a docs only documentation, your configuration could look like this:

module.exports = {
  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          // with the change below, docs are server over `/` instead of `/docs/`
          routeBasePath: "/",
        },
      },
    ],
  ],
  plugins: [
    [
      "docusaurus-graphql-plugin",
      {
        schema: "schema.graphql",

        // routeBasePath defaults to `/docs/api/` which will not work if docs are server over `/`
        routeBasePath: "/api/",
      },
    ],
  ],
};