GraphQL Explorer (alpha)
GraphQL Explorer is Square's interactive in-browser tool for writing, validating, and testing GraphQL queries for Square APIs. GraphQL Explorer provides auto-generated documentation of the available schemas. To access GraphQL Explorer, sign in to your Square developer account and access GraphQL Explorer at https://developer.squareup.com/explorer/graphql.
You can use GraphQL Explorer to do the following:
Query an externally accessible GraphQL endpoint.
Retrieve data from any graph for a single merchant using an OAuth token (and filtering to a merchant ID).
Query any graphs individually, restricted only by rate and cost limiting.
Currently, you can run queries on several graphs of the Square APIs. For this alpha release, you can only query and view existing graphs.
The following APIs are supported in Square GraphQL:
To use GraphQL Explorer, enter your query in the left pane to see live syntax and validation errors highlighted within the text.
Runs the query in the query pane.
Shows the access codes available for the signed-in account. Select one.
Lists the sample queries that can appear in the query pane.
Adds highlighting and color to the query pane.
The query pane, which provides syntax and schema checking.
Where you enter query variables. Not currently available.
Shows the access code used for the query.
The results window.
Shows the schema and documentation.
Query variables do not work at this time.
GraphQL Explorer provides schema documentation you can use to construct queries. The schema documentation, which is shown when you select the Docs button, shows the correct query format. You write the query in the query pane. The following example shows how to use the schema documentation to create a query.
You can also use the code hint that appears while typing in the editor for query help.
To create a simple merchant query using the schema documentation:
Determine which graph you want to create a query for. This example uses the Merchant graph to create a merchant query.
In the schema documentation, look at what parameters the merchant query takes. All queries require a filter parameter to specify a merchant ID or a merchant and a location ID. This example creates a filter that filters on merchant ID. The code takes the format
merchants(filter: MerchantsFilter): Merchant. Define the
Use your merchant ID as the value for the merchant filter. Place this code in the braces of the filter object.
The completed filter looks similar to the following:
The next part of the query includes the set of fields you want returned from the query. You add this part of the query immediately after the filter and before the final bracket. Look at the return type from the type of query you are creating to determine what fields are returned. For this example, use the schema to search for MerchantConnection and then under Fields, find nodes and choose Merchants.
In the Fields list, add the fields that you want to retrieve. Note that some fields have additional nested fields such as the Location type for the
The query is ready to run. Note that in this example, the query variable
$merchantIdis used. You can also enter the value directly inside the query.
The complete query is shown as follows: