Introspection - Get a GraphQL Schema
The GraphQL Schema
The GraphQL web service defines exactly the data objects and types you can query in a so called schema. And a GraphQL web service allows you to ask for the GraphQL schema it supports. This is called Introspection. Introspection is the reason that a developer environment with a graphical user interface like Insomnia makes it easier to discover GraphQL compared to the command line interface of CURL: the Insomnia interface is able to give suggestions on the objects and types that are available in the GraphQL schema.
Define your first GraphQL request in Insomnia
You will create and save a new request in the graphical user interface of Insomnia for each exercise.
Click on the +
sign to create a new API request.
On the next screen you give a name to the API request and you need to specify the HTTP Verb (always POST for GraphQL except when you want to retrieve the GraphQL schema which is done with a GET). On this form you can also specify the format of the body (obviously you will select GraphQL as the format for your body).
Next you need to specify the the endpoint URL: this is done in the top header bar after the HTTP verb.
To specify the authorization options click on the Auth tab. Select Bearer Token to specify the personal access token.
Finally you need to specify the headers. You just need to specify the account in the x-Xurrent-account
header. By default Insomnia adds the Content-Type
header with value application/json
which is exactlty the content type required.
Exercise:
Create a GraphQL request to get the Xurrent GraphQL schema. To retrieve the complete schema you just need to perform a GET
request to the GraphQL service url. You must include a personal access token, an account header is not required.
Specify the GET method, the personal access token and the Service URL. Insomnia will display the nicely formatted response in the right pane.
You can find the complete Xurrent GraphQL API library on the Xurrent Developer Website. When you design and build an integration you will probably also consult these pages to check the Xurrent GraphQL schema.