Skip to main content

Use GraphQL Playground

Overview

GraphQL is a query language for APIs that you can use to request exactly the data you need, making it possible to get all required data in a few requests. This document explains how to query Sky Mavis GraphQL schemas and how to explore them using the GraphQL Playground.

Endpoint

GraphQL endpoint
https://api-gateway.skymavis.com/graphql/[name]

Schemas

Sky Mavis offers the following GraphQL schemas:

To access any of these schemas, replace [name] with katana, marketplace, or mavis-marketplace, respectively.

Prerequisites

Learn the basics

Before getting to the schema, you might want to know the basic interface of queries in GraphQL. A query contains the following elements:

  • The optional keyword query. If no keyword is specified at the beginning of a request, the processor assumes the request is a query.
  • An optional operation name. If you use variables the operation name is required.
  • The query name
  • Arguments
  • Output fields
GraphQL basics

The GraphQL documentation is a useful resource for beginners to learn the basics. We recommend reading more about GraphQL if this is your first time using it.

Get an API key

To get an API key, create and set up an app in the Developer Console.

Use GraphQL Playground

The GraphQL Playground is a GraphQL client you can use to explore the available GraphQL API schemas and run GraphQL queries right from the browser.

This may be handy in different scenarios, for example when you need to manually execute a particular GraphQL query or mutation, or even while actively developing an app.

To access the playground, go to Developer Console > GraphQL Playground.

Build your query

To build a query in the GraphQL playground, take these steps:

  1. Select the schema at the top navigation bar.
  2. Select the fields you need for the query or copy the example in the next section.
  3. Click Execute query.

The response appears to the right of the query.

Use aliases and fragments

With GraphQL, you can use aliases to fetch multiple objects of the same type but with different arguments. This means that you can get the names and other details from both parents of the preceding example in one request.

same{
sire: axie(axieId:149256){
...AxieDetails
}
matron: axie(axieId:149294){
...AxieDetails
}
}
fragment AxieDetails on Axie {
name,
owner,
breedCount
}

Send an HTTP POST request to the endpoint. Make sure to use your API key.

curl -X POST -H "Content-Type: application/json" -H "X-API-Key: <YOUR_API_KEY>" --data '{
"query": "query={sire:axie(axieId:149256){...AxieDetails}matron:axie(axieId:149294){...AxieDetails}}fragment AxieDetails on Axie{name,owner,breedCount}"
}' https://api-gateway.skymavis.com/graphql/marketplace

You should see output similar to this:

{
"data": {
"sire": {
"name": "Lamsterdance",
"owner": "0xc96e2c8a1363ac0b702afd8b9419c8056c65baad",
"breedCount": 4
},
"matron": {
"name": "0.0125",
"owner": "0xa06d8278b5cf6217ff911a40da14797778fe8628",
"breedCount": 5
}
}
}

As you can see, fragments can be used to construct a set of fields, which you can include in every query by calling the ...FragmentName.

Example

Get the name of an Axie

Now that you have the API key and schema, let's try to get the name of an Axie. To achieve this, you need to query for the object axie.

Pass the argument axieId so that you can search for a specific Axie. Because you're only interested in Axie's name and its parent's IDs, you only need to pass the fields name, sireId and matronId.

{
axie(axieId:149650){
name,
sireId,
matronId
}
}

Send an HTTP POST request to the endpoint. Make sure to use your API key.

curl -X POST -H "Content-Type: application/json" -H "X-API-Key: <YOUR_API_KEY>" --data '{
"query": "{axie(axieId:149650){name,sireId,matronId}}"
}' https://api-gateway.skymavis.com/graphql/marketplace

You should see a response similar to the following:

{
"data": {
"axie": {
"name": "Froot Loop",
"sireId": 149256,
"matronId": 149294
}
}
}

See also

Was this helpful?