Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Latest commit

 

History

History
139 lines (92 loc) · 6.33 KB

File metadata and controls

139 lines (92 loc) · 6.33 KB

Custom Endpoints

Create custom schemas, with custom access rules for different users, each available under its own endpoint.

Description

A GraphQL server normally exposes a single endpoint for retrieving and posting data.

In addition to supporting the single endpoint, the GraphQL API also makes it possible to create custom endpoints, providing different schema configurations to deal with the needs from different targets, such as:

  • Some specific client or user
  • A group of users with more access to features (such as PRO users)
  • One of the several applications, like mobile app or website
  • 3rd-party APIs
  • Any other

The custom endpoint is a Custom Post Type, and its permalink is the endpoint. An endpoint with title "My endpoint" and slug my-endpoint will be accessible under /graphql/my-endpoint/.

Custom endpoint editor

Clients

Each custom endpoint has its own set of clients to interact with:

✅ A GraphiQL client, available under the endpoint + ?view=graphiql (eg: /graphql/my-endpoint/?view=graphiql).

Module GraphiQL for Custom Endpoints must be enabled.

Custom endpoint's GraphiQL client

✅ An Interactive schema client, available under the endpoint + ?view=schema (eg: /graphql/my-endpoint/?view=schema).

Module Interactive Schema for Custom Endpoints must be enabled.

Custom endpoint's Interactive schema

Creating a Custom Endpoint

Clicking on the Custom Endpoints link in the menu, it displays the list of all the created custom endpoints:

Custom Endpoints in the admin

A custom endpoint is a custom post type (CPT). To create a new custom endpoint, click on button "Add New GraphQL endpoint", which will open the WordPress editor:

Creating a new Custom Endpoint

When the custom endpoint is ready, publish it, and its permalink becomes its endpoint URL. Links to the endpoint (and source and clients) are shown on the "Custom Endpoint Overview" sidebar panel:

Custom Endpoint Overview

Appending ?view=source to the permalink, it will show the endpoint's configuration (as long as the user is logged-in and the user role has access to it):

Custom endpoint source

By default, the custom endpoint has path /graphql/, and this value is configurable through the Settings:

Custom endpoint Settings

Schema configuration

Defining what elements the schema contains, and what access will users have to it, is defined in the schema configuration.

So we must create a create a schema configuration, and then select it from the dropdown:

Selecting the schema configuration

Organizing Custom Endpoints by Category

On the sidebar panel "Endpoint categories" we can add categories to help manage the Custom Endpoint:

Endpoint categories when editing a Custom Endpoint

For instance, we can create categories to manage endpoints by client, application, or any other required piece of information:

List of endpoint categories

On the list of Custom Endpoints, we can visualize their categories and, clicking on any category link, or using the filter at the top, will only display all entries for that category:

List of Custom Endpoints with their categories

Filtering Custom Endpoints by category

Editor Inputs

These inputs in the body of the editor are shipped with the plugin (more inputs can be added by extensions):

Input Description
Title Custom endpoint's title
Schema configuration From the dropdown, select the schema configuration that applies to the custom endpoint, or one of these options:
  • "Default": the schema configuration is the one selected on the plugin's Settings
  • "None": the custom endpoint will be unconstrained
  • "Inherit from parent": Use the same schema configuration as the parent custom endpoint.
    This option is available when module "API Hierarchy" is enabled, and the custom endpoint has a parent query (selected on the Document settings)
Options Select if the custom endpoint is enabled.
It's useful to disable a custom endpoint it's a parent query in an API hierarchy
GraphiQL Enable/disable attaching a GraphiQL client to the endpoint, accessible under ?view=graphiql
Interactive Schema Enable/disable attaching an Interactive schema client to the endpoint, accessible under ?view=schema
API Hierarchy Use the same query as the parent custom endpoint.
This section is enabled when the custom endpoint has a parent query (selected on the Document settings)

These are the inputs in the Document settings:

Input Description
Permalink The endpoint under which the custom endpoint will be available
Categories Can categorize the custom endpoint.
Eg: mobile, app, etc
Excerpt Provide a description for the custom endpoint.
This input is available when module "Excerpt as Description" is enabled
Page attributes Select a parent custom endpoint.
This input is available when module "API Hierarchy" is enabled