Using GraphQL body type

In this page, we’ll show you how to use GraphQL Body type in your API collections.

GraphQL is a query language for APIs that gets the exact and specific data your app needs in a single request. Unlike REST APIs, you will be able to access the full capabilities of your data from a single endpoint.

Apps using GraphQL are fast and stable, even on slow mobile connections, because they control the data they get by returning predictable results.

About GraphQL queries and mutations

In this tutorial, we will use countries playground as an example to retrieve the information of all the countries of a specific continent. In case you’re using another GraphQL API, you will need to read its documentation and schema. Here's a list of public GraphQL API's you can try.

GraphQL APIs queries are created by defining types and fields and they are used to fetch data. Types are used to avoid writing manual parsing code and to ensure that Apps only ask for what’s possible and provide clear and helpful errors. See more information about GraphQL queries here.

Mutations allows you to modify your data. It can be used to insert, update and delete data. With GraphQL, it is semantically separated to read a "query" from to write a "mutation" and both have intelligible names. See more information about GraphQL mutations here.

How to set it up in Bravo:

  1. Set the request type to POST and add the URL endpoint. All GraphQL requests should be executed with a POST request and remember that you can use a single endpoint for different requests.

  2. In the request’s Body, select GraphQL and introduce your valid query.

3. Like REST API's requests, you can also use variables in GraphQL queries. In this example, we are filtering all countries of a specific continent and the variable we are using is $code, as specified in the query. Once you enter a query with a variable, a variable field will be automatically populated below and you will have to put the value of it, which has to be ${code}. Permitted characters: lowercase a-z, uppercase A-Z, 0 to 9, underscore (_) and dash (-). No spacing.

4. Next step is sending a test request against our database, to make sure the request is built correctly. For that, we'll go to the Test Values section inside the API request, and indicate mock data for the variables we previously defined. The Key name for the test value must match the name we defined for the variable (case-sensitive).

5. Finally, click on Send and Received Data to select the information you need from your database depending if you're setting up a request for a list or a detail page.

Last updated