2017 © Pedro PelĆ”ez
 

silverstripe-vendormodule graphql-devtools

Tools to help developers building new applications on SilverStripeā€™s GraphQL API

image

silverstripe/graphql-devtools

Tools to help developers building new applications on SilverStripeā€™s GraphQL API

  • Wednesday, July 18, 2018
  • by tractorcow
  • Repository
  • 6 Watchers
  • 4 Stars
  • 3,360 Installations
  • JavaScript
  • 0 Dependents
  • 1 Suggesters
  • 7 Forks
  • 7 Open issues
  • 1 Versions
  • 18 % Grown

The README.md

Dev tools for silverstripe-graphql

Tools to help developers building new applications on SilverStripeā€™s GraphQL API, (*1)

Installation

$ composer require --dev silverstripe/graphql-devtools

Requirements

What it does

This module adds an implementation of graphiql, an in-browser IDE for GraphQL servers. It provides browseable documentation of your schema, as well as autocomplete and syntax-checking of your queries., (*2)

Accessing the IDE

In GraphQL 3.x, it can be accessed at /dev/graphiql/., (*3)

In GraphQL 4.x, it can be accessed at /dev/graphql/ide., (*4)

This is because GraphQL 4 has its own DevelopmentAdmin controller., (*5)

The GraphQL v4 version of the module allows you to clear your schema by calling the /dev/graphql/clear task., (*6)

Security

By default, the tool has the same restrictions as other development tools like dev/build:, (*7)

  • In "dev" mode, it's available without authentication
  • In "test" and "live" mode, it requires ADMIN permissions
  • It's installed with composer require --dev by default. In most deployment contexts that'll mean it's not available on environments in "test" or "live" modes, (*8)

    , (*9)

    Configuration

    In most installations of SilverStripe, there are at least two GraphQL servers running -- one for the admin (admin/graphql) and one for the user space (/graphql). By default, only the default schema will show, but this is configurable., (*10)

    Showing multiple schemas

    Important: Due to a limitation in the GraphQL Playground library, showing multiple schemas will disable the persistence of IDE state across page refreshes., (*11)

    Also important: When changing the available schemas, be sure to clear the local storage in your browser, otherwise, you'll get inconsistent state., (*12)

    You can configure the visible schemas in the controller., (*13)

Show a select list of schemas ```yaml SilverStripe\GraphQLDevTools\Controller: # show two schemas schemas: - default - admin # default schema that is selected default_schema: admin, (*14)


Show all schemas ```yaml SilverStripe\GraphQLDevTools\Controller: # show two schemas schemas: '*' default_schema: default

Further, you can override the config in the request, by using ?schema=<schemaName>, e.g. http://example.com/dev/graphql/ide?schema=mySchema., (*15)

If you're using a custom controller for your GraphQL endpoint

The IDE finds schemas by checking Director for routes that map to a SilverStripe\GraphQL\Controller instance. If for some reason you're using a custom controller, you might get an error: "Could not find your default schema 'default'. You will need to add one to the SilverStripe\Control\Director.rules config setting.", (*16)

To avoid this, you can explicitly map your graphql route to a schema in your Director config:, (*17)

SilverStripe\Control\Director:
  rules:
    graphql:
      Controller: '%$MyCustomController'
      Schema: default

Upgrading and maintaining the IDE

The library running the IDE is GraphQL Playground. It is served from your local environment as an exposed resource. The setup is based on their "HTML Page" example seen here, which uses remote bundle files served from a CDN. This repository uses a manually created bundle file copied directly from the CDN. This may seem like a convoluted approach, but the main benefits are:, (*18)

  • It allows offline use
  • It does not require setting up a build chain or installing NPM dependencies
  • There is no need for SRI protection, (*19)

    To upgrade GraphQL Playground, refer to the example linked above and use their CDN to download the latest distribution and drop it into this repository. Be sure to update the comment at the top of the bundle.js file to track the URL it was downloaded from., (*20)

The Versions

18/07 2018

dev-master

9999999-dev

Tools to help developers building new applications on SilverStripeā€™s GraphQL API

  Sources   Download

The Requires