Files
backstage/plugins/graphiql
blam 48aacfbe17 Merge branch 'master' of github.com:spotify/backstage into blam/react-router
* 'master' of github.com:spotify/backstage: (89 commits)
  Use URLSearchParams
  Use location?.type once more
  chore(catalog): clean up CatalogTable, use only Entity
  chore(catalog): clean up ComponentPage, use only Entity
  chore(catalog): tweak getEntityByName a bit, handle 404s properly
  chore(catalog/star): only set the cache if there are entries from the response
  chore(catalog/star): added a comment about why we are using a simple cache here
  chore(catalog/star): removing msw dependency, wrong branch
  chore(catalog): consistent use of named exports
  chore(msw): Added msw dependency
  chore(catalog/star): fixing issues with unmocked deps
  chore(catalog/star): adding a simple cache to stop flicker as a stopgap
  chore(catalog/star): reworking how the starring works, it now stores uri sort of references for entities
  fix(core): Tabs useEffect dependency list
  docs: format with prettier (#1218)
  Optional namespace and name as one part of URL
  docs/auth: added overview, oauth description and glossary
  docs: added plantuml generation script
  docs: added prettier config
  Remove deleted UserBadge component from Sidebar story
  ...
2020-06-11 17:36:19 +02:00
..
2020-04-25 16:51:22 +02:00

@backstage/plugin-graphiql

This plugin integrates GraphiQL as a tool to browse GraphiQL endpoints inside Backstage.

The purpose of the plugin is to provide a convenient way for developers to try out GraphQL queries in their own environment. By exposing GraphiQL as a plugin instead of a standalone app, it's possible to provide a preconfigured environment for engineers, and also tie into authentication providers already inside Backstage.

Getting Started

Installing the plugin

Start out by installing the plugin in your Backstage app:

yarn add @backstage/plugin-graphiql

Then add an entry to your App's plugins.ts to import the plugin.

The plugin registers a /graphiql route, which you can link to from the Sidebar if desired.

Adding GraphQL endpoints

For the plugin to function, you need to supply GraphQL endpoints through the GraphQLBrowse API, which is done by implementing the GraphQLBrowseApi exported by this plugin.

If all you need is a static list of endpoints, the plugin exports a GraphQLEndpoints class that implements the GraphQLBrowseApi for you. Here's and example of how you could expose two GraphQL endpoints in your App:

import {
  graphQlBrowseApiRef,
  GraphQLEndpoints,
} from '@backstage/plugin-graphiql';

// Implement the Graph QL browse API using a static list of endpoints
const graphQlBrowseApi = GraphQLEndpoints.from([
  // Use the .create function if all you need is a static URL and headers.
  GraphQLEndpoints.create({
    id: 'gitlab',
    title: 'GitLab',
    url: 'https://gitlab.com/api/graphql',
    // Optional extra headers
    headers: { Extra: 'Header' },
  }),
  {
    id: 'hooli-search',
    title: 'Hooli Search',
    // Custom fetch function, this one is equivalent to using GraphQLEndpoints.create()
    // with url set to https://internal.hooli.com/search
    fetcher: async (params: any) => {
      return fetch('https://internal.hooli.com/search', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(params),
      }).then(res => res.json());
    },
  },
]);

// ApiRegistry builder created somewhere in your App
const builder = ApiRegistry.builder();

// Add the instance to the API registry
builder.add(graphQlBrowseApiRef, graphQlBrowseApi);