Creating an API
Creating an APICreating a custom endpoint

Creating a custom endpoint

In addition to the single endpoint, Gato GraphQL also supports custom endpoints, to retrieve and post data for a custom schema (containing only a subset of the available types) and user validation rules, as to deal with the needs from different users and applications.

We can create as many custom endpoints as needed.

For instance, we can create a custom endpoint for:

  • Some specific client or user, under /graphql/my-client/
  • A group of users with more access to features (such as PRO users), under /graphql/pro-users/
  • Provide data to our mobile app, under /graphql/mobile-app/
  • Give access to some 3rd-party API, under /graphql/external-api/
  • Others

Custom Endpoint editor

Executing the custom endpoint in an application

Please follow the instructions on guide Connecting to the GraphQL server from a client.

Accessing all custom endpoints

Clicking on "Custom Endpoints" on the plugin's menu, it displays the list of all the created custom endpoints:

Custom Endpoints in the admin
Custom Endpoints in the admin

Creating a new custom endpoint

Click on button "Add New GraphQL endpoint" to open the WordPress editor:

Creating a new Custom Endpoint

Give it a title, make sure the permalink is the desired one, select the schema configuration, and adjust the options. When ready, click on the Publish button, and the custom endpoint is created, using the configured permalink as endpoint URL.

Links to the endpoint (and source and clients) are shown on the "Custom Endpoint Overview" sidebar panel:

Custom Endpoint Overview

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 (or use none, or the default one):

Selecting the schema configuration

Private endpoints

By setting the status of the Custom Endpoint as private, the endpoint can only be accessed by the admin user. This prevents our data from being unintentionally shared with users who should not have access to the data.

For instance, we can create private Custom Endpoints that help manage the application, such as retrieving data to create reports with our metrics.

Private Custom Endpoint

Password-protected endpoints

If we create a Custom Endpoint for a specific client, we can now assign a password to it, to provide an additional level of security that only that client will access the endpoint.

Password-protected Custom Endpoint

When first accessing a password-protected endpoint (whether accessing the endpoint directly, or its GraphiQL or Interactive Schema clients), we encounter a screen requesting the password:

Password-protected Custom Endpoint: First access

Once the password is provided and validated, only then the user will access the intended endpoint or client:

Password-protected Custom Endpoint: After authorization

Creating an endpoint hierarchy

Please read the instructions on creating an API hierarchy.

Disabling the custom endpoint

In the options, set "Enabled" to false to disable the custom endpoint.

This feature can be useful when making the custom endpoint be part of an API hierarchy, to provide a common behavior to its child custom endpoints, but without needing itself be executed.

Describing the custom endpoint

Use the "Excerpt" field, from the Document settings panel, to give a description to the custom endpoint.

Find more information in guide Adding a description to the API.

Endpoint clients

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

GraphiQL client

Add ?view=graphiql to the endpoint to access its GraphiQL client:

Custom endpoint's GraphiQL client

The GraphiQL client can also be opened when editing the Custom Endpoint, under sidebar panel "Custom Endpoint Overview":

Custom endpoint's link to the GraphiQL client in the editor

Likewise, the client can be opened from the Custom Endpoints list page, on link "GraphiQL" when hovering on the entry:

Custom endpoint's link to the GraphiQL client in the list
Custom endpoint's link to the GraphiQL client in the list

To disable the GraphiQL client, set option "Expose GraphiQL client?" to false in the Custom Endpoint editor.

Interactive Schema (Voyager) client

Add ?view=schema to the endpoint to access its Interactive Schema client, to visualize and interact with the endpoint's schema:

Custom endpoint's Voyager client

The Interactive Schema client can also be opened when editing the Custom Endpoint, under sidebar panel "Custom Endpoint Overview":

Custom endpoint's link to the Interactive Schema client in the editor

Likewise, the client can be opened from the Custom Endpoints list page, on link "Interactive Schema" when hovering on the entry:

Custom endpoint's link to the Interactive Schema client in the list
Custom endpoint's link to the Interactive Schema client in the list

To disable the Interactive Schema client, set option "Expose the Interactive Schema client?" to false in the Custom Endpoint editor.

Testing the endpoint before publishing online

A custom endpoint with status draft or pending is available to the schema editor users only. This gives them the ability to:

  • Execute GraphQL queries against it
  • Access the endpoint's GraphiQL and Voyager clients

Then, we can create a custom endpoint, assign a Schema Configuration, publish it as draft or pending, and test it (eg: checking that its Access Control rules are appropriate).

Once approved, only then we set its status as publish, making the custom endpoint available to everyone.

Viewing the source

Appending ?view=source to the endpoint, 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


Configuration in the WordPress editor

These are the inputs in the body of the editor:

InputDescription
TitleCustom endpoint's title
Schema configurationFrom 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)
OptionsCustomize the behavior of the custom endpoint:
  • Enabled?: If the custom endpoint is enabled.
    It's useful to disable a custom endpoint it's a parent query in an API hierarchy
  • Expose GraphiQL client?: Enable/disable attaching a GraphiQL client to the endpoint, accessible under ?view=graphiql
  • Expose the Interactive Schema client?: Enable/disable attaching an Interactive schema client to the endpoint, accessible under ?view=schema
  • Inherit query from ancestor(s)?: Use the same query 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)

These are the inputs in the Document settings:

InputDescription
PermalinkThe endpoint under which the custom endpoint will be available
CategoriesCan categorize the custom endpoint.
Eg: mobile, app, etc
ExcerptProvide a description for the custom endpoint.
This input is available when module "Excerpt as Description" is enabled
Page attributesSelect a parent custom endpoint.
This input is available when module "API Hierarchy" is enabled