GraphQL Explorer Overview
Beta release
This is pre-release documentation for an API in public beta and is subject to change.
Square GraphQL Explorer is an interactive web application that lets you write, validate, and send queries for Square data. You can use GraphQL Explorer features (such as code completion, syntax validation, and on-page schema documentation) to help you write queries. You can then run the queries against your own Square data. To access GraphQL Explorer, open https://developer.squareup.com/explorer/graphql and sign in to your Square account.
You can use GraphQL Explorer to:
Query the GraphQL endpoint in the Sandbox
An isolated server environment used for testing.Browse the schema documentation to find available fields, type information, and query syntax.
Retrieve data for a single merchant using a personal or OAuth access token
Grants permission to access data in a Square account, such as customer, order, and payment information.In a single query, you can retrieve data for one or more supported graphs:
Cards
Catalog
Customers
Inventory
Merchants
Orders
Payments
Refunds
Note
Square GraphQL supports query operations only. Mutations and subscriptions aren't supported. Queries are subject to rate and cost limiting.
To use GraphQL Explorer, enter your query in the left pane and then run the query to see real-time results against your Square data.
1. Sandbox or Production toggle
Lets you choose between the Sandbox or production environment. This selection determines whether GraphQL Explorer sends queries to the Sandbox endpoint or the production endpoint.
2. Run request button
Sends the current query and any query variables to Square GraphQL. Alternatively, you can use the Ctrl-Enter
keyboard shortcut to send the query.
3. Add access token button
Lists the personal access tokens for the signed-in account. When you select an access token, it's added to the Request Headers pane and used for your queries. If you switch between Sandbox and production, you must reselect an access token that's valid for the environment.
4. Sample query button
Lets you select a sample query to load into the query pane. Square provides a sample query for every graph entry point. All sample queries use query variables, so you need to enter valid values into the Query Variables pane before running the query.
5. Prettify button
Applies proper spacing and indentation and removes comments and extra line breaks.
6. Query pane
Lets you enter and edit queries and provides code completion, code hints, and syntax and schema highlighting and validation. For code completion, you can begin typing or use Ctrl-Space
to show suggestions.
7. Query Variables pane
Stores the variables used in the query and their values. All sample queries use query variables. For more information, see Variables.
8. Request Headers pane
Stores the request headers for the query. All queries require an Authorization
header and bearer access token. If you want to test OAuth permissions, paste the OAuth access token directly into this pane.
You can include "x-graphql-include-debug": 1
in the request headers to return an extensions
object with debugging information. Currently, this object contains the query's complexity score
and a request ID that you can provide to Square support.
9. Results pane
Shows real-time responses with results and error information for the queries you run.
10. Documentation Explorer
Provides searchable schema documentation. If this pane is hidden, open it using the Docs button. For more information, see Using the schema to create a query.
In addition, you can toggle between light and dark mode or leave feedback using the controls at the bottom of the page.
GraphQL Explorer provides schema documentation in the Documentation Explorer pane. As you write queries, you can check the schema to find available fields, type information, and valid query syntax.
The following steps show how to use the schema documentation to create a query that gets open orders and information about the customer associated with each order.
Sign in to GraphQL Explorer using your Square account. If the Documentation Explorer pane isn't showing, choose the Docs button to open it.
Note
Don't have a Square account? It only takes a few minutes to sign up and create a free account.
Choose Add access token and select an access token
Grants permission to access data in a Square account, such as customer, order, and payment information.Get your merchant ID to use for the example query. Remove any existing content from the query pane and enter the following query:
Most Square GraphQL queries have a required
merchantId
filter.Choose Run request. You use the returned
id
in a later step.The
currentMerchant
entry point can also be used to query for other merchant fields, such asbusinessName
,currency
, andlocations
.
In Documentation Explorer, choose the
Query
root type to see available entry points, and then chooseorders
.You can see that the
orders
entry point is anOrderConnection
object that accepts several arguments.In the query pane, start writing your query. Remove any existing content and enter the following snippet, which uses "OpenOrders" as the optional operation name:
The example query you're building only includes
orders
, but queries can contain multiple entry points.Did you know?
In the query pane, you can hover over the
orders
field to open a code hint that provides a short description of the field with links to relevant schema documentation. The query pane also provides code completion and syntax validation to help you write queries.
This example query filters orders by merchant ID and the OPEN
state.
In Documentation Explorer, choose the
OrderFilter
type for thefilter
argument. Scroll down to themerchantId
andstate
filters.Navigate through the components that make up the
merchantId
andstate
filters to find the required syntax.merchantId
uses the following syntax:
merchantId: { equalToAnyOf: [ID!] }
state
uses the following syntax:
state: { equalToAnyOf: [OrderState!] }
The following snippet represents the complete
filter
argument for the example query:Add the
filter
snippet to your query. In the query pane, replace# query arguments go here
with thefilter
argument. Then, replace themerchantId
value with your merchant ID and thestate
value withOPEN
.Your query should look like the following example (where
<YOUR_MERCHANT_ID>
is your merchant ID). You can ignore any mismatched indentation.The syntax for the
filter
argument is now added to the query. The next part of the query specifies the order and customer data you want to retrieve.
Queries must explicitly specify the fields to retrieve. This example query gets information about the order and the customer associated with the order. In the following steps, you navigate through the schema to find fields to add to the query:
In Documentation Explorer, return to
orders
and choose theOrderConnection
type. Note that thenodes
field is an array ofOrder
objects.Choose the
Order
type to see the available order fields. For this query, you want to retrieve theid
,createdAt
, andcustomer
fields for the order. Note that thecustomer
field is aCustomer
object.Choose the
Customer
type to see the available customer fields. For this query, you want to retrieve thefamilyName
,phoneNumber
, andaddress
fields for the customer associated with the order. Note that theaddress
field is anAddress
object.Choose
Address
to see the available address fields. For this query, you just want to retrieve thepostalCode
field of the customer's address.The following snippet represents the hierarchical list of fields you want to retrieve, starting with the
nodes
field:Add the
nodes
snippet to your query. In the query pane, replace# requested fields go here
with the fields you want to retrieve. Your query should look like the following example:
Choose Run request. The following is an excerpt of an example response:
Keep in mind that each tender (payment) for an order might also have an associated customer. The customer associated with the payment might not be the same one that is associated with the order.
Some Square GraphQL graphs (such as Payments and Refunds) follow the GraphQL Cursor Connection Specification. For these graphs, the query specifies a top-level edges
list instead of nodes
, as shown in the following Payments query:
Learn how to use variables to make your queries easier to reuse. For example, instead of specifying the merchant ID directly in the query, you can use a variable in the query and pass in the merchant ID separately.
Learn how to use pagination to retrieve paged responses.
If you need more assistance, contact Developer Support or ask for help in the Developer Forums.