Docs
Try Apollo Studio

Embedding the Explorer


If you have a public variant of your graph, you can embed the Apollo Studio Explorer in a webpage that you can then provide to your graph's consumers. This enables those consumers to test out operations from your own website.

For example, here's an embedded Explorer for an Apollo example graph. Try it out!

Setup

Before you proceed, make sure you have a public variant of your graph in Apollo Studio.

  1. Go to Apollo Studio and open the public variant you want to use with the embedded Explorer.
  2. Go to the variant's Explorer page.

  3. Under the Explorer's Settings tab, find Embed Explorer and click Copy code snippet.

    The following dialog appears:

    Explorer embed dialog
  4. Use the options in the dialog to customize the embedded Explorer's appearance and behavior to your liking.

  5. Click Copy to copy the snippet, then paste it into your code.

See below for descriptions of options shown in the dialog, along with advanced options that aren't shown.

Embedding with a default operation

You can also open the Embed Explorer dialog from the Explorer's operation editor. Open the ••• menu next to an operation and click Embed this operation:

Explorer embed link

This configures your embedded Explorer to include all of the following automatically on load:

  • The operation you selected
  • Any variable values defined in your current Explorer tab that are used in the selected operation
  • All headers defined in your current Explorer tab

Options

The EmbeddedExplorer object takes an options object with the following structure (individual options are described below):

{
graphRef: 'acephei@current',
endpointUrl: 'https://acephei-gateway.herokuapp.com',
persistExplorerState: false,
initialState: {
document: `query ExampleQuery {
me {
id
}
}
`,
variables: { 'Variable1': 'ExampleValue' },
headers: { 'Header1': 'ExampleValue' },
displayOptions: {
showHeadersAndEnvVars: true,
docsPanelState: 'open',
theme: 'light',
},
},
handleRequest: (endpointUrl, options) => {
return fetch(endpointUrl, {
...options,
headers: {
...options.headers,
authorization: `token ${token}`
},
})
},
}

Top-level options

These are the top-level fields you can include in the options object you pass to new EmbeddedExplorer:

Name /
Type
Description
graphRef

string

Required. The graph ref for the public variant you want to use the embedded Explorer with. Has the format graph-id@variant-name. This value is automatically populated in the Explorer's embed snippet.

The Explorer fetches this variant's schema from Apollo Studio to populate its Documentation panel and enable code completion.

If you omit this option, the Explorer does still load, but it doesn't know which schema to fetch. This prevents the Explorer from providing critical features like documentation and code completion.

endpointUrl

string

The endpoint URL of the public variant you want to use the embedded Explorer with. This value is automatically populated in the Explorer's embed snippet.

Required, unless you specify your own fetcher with the handleRequest option.

persistExplorerState

true | false

If true, the embedded Explorer uses localStorage to persist its state (including operations, tabs, variables, and headers) between user sessions. This state is automatically populated in the Explorer on page load.

If false, the embedded Explorer loads with an example query based on your schema (unless you provide document).

The default value is false.

handleRequest

(url, options) => Promise

By default, the embedded Explorer uses the fetch API to send requests to your endpointUrl. You can instead pass a custom fetcher that's used to run all operations.

You might want to do this if you need to include specific headers in every request made from your embedded Explorer.

initialState

Object

An object containing additional options related to the state of the embedded Explorer on page load.

For supported subfields, see initialState options.

initialState options

These are the fields you can include in the initialState option you pass to new EmbeddedExplorer:

Name /
Type
Description
document

string

A URI-encoded operation to populate in the Explorer's editor on load.

If you omit this, the Explorer initially loads an example query based on your schema.

If persistExplorerState is true and you provide this option, the Explorer loads any of the user's tabs from localStorage, and it also opens a new tab with this operation.

Example:

intialState: {
document: `
query ExampleQuery {
books {
title
}
}
`;
}
variables

string

A URI-encoded, serialized object containing initial variable values to populate in the Explorer on load.

If provided, these variables should apply to the initial query you provide for document.

Example:

intialState: {
variables: {
userID: "abc123"
},
}
headers

string

A URI-encoded, serialized object containing initial HTTP header values to populate in the Explorer on load.

Example:

initialState: {
headers: {
authorization: 'Bearer abc123';
}
}

displayOptions options

These are the fields you can include in the initialState.displayOptions option you pass to new EmbeddedExplorer:

Name /
Type
Description
docsPanelState

"open" | "closed"

If open, the Explorer's Documentation panel (the left column) is initially expanded. If closed, the panel is initially collapsed.

The default value is open.

showHeadersAndEnvVars

true | false

If true, the embedded Explorer includes the panels for setting request headers and environment variables. If false, those panels are not present.

The default value is true.

theme

"dark" | "light"

If dark, the Explorer's dark theme is used. If light, the light theme is used.

The default value is dark.

Edit on GitHub
Previous
Operation collections
Next
Additional features