What is GraphQL and how does it interact with the Enjin Platform API?
Learn more about GraphQL and how the Enjin Platfom uses it through our API.
GraphQL is a modern query language for APIs that allows you to define the data structure of your queries and ask for exactly what you want and nothing more.
GraphQL queries access not just the properties of one resource but also smoothly follow references between them. While typical REST APIs require loading from multiple URLs, GraphQL APIs get all the data your app needs in a single request.
Operations
Query: READ operations are performed by GraphQL queries, these do not change data.
Mutation: You will use mutations to perform all other operations to modify data.
Object Types
Object types are sets of fields that are used to define the set of data you can query from the API.
1
query{
2
3
}
4
5
mutation{
6
7
}
Copied!
Fields
Fields are used to ask for specific object properties.
Each object has fields that can be queried by name in order to query for the properties you need.
1
query{
2
EnjinToken{
3
id
4
}
5
}
Copied!
Arguments
You can determine the return value of a query by passing arguments to it. This narrows down the results and allows you to only get what you're after.
In the following example, the object is GetAsset, the requested field is id, the arguments are id, name, createdAt, updatedAt, wallet and ethAddress.
1
query{
2
GetAsset(id:"708000000000088e"){
3
id
4
name
5
createdAt
6
updatedAt
7
wallet{
8
ethAddress
9
}
10
}
11
}
Copied!
For further reference on how GraphQL works, you can also refer to their documentation here
GraphiQL: GraphQL's Visual Interface
Probably the most user-friendly feature of GraphQL is its visual interface, an in-browser tool for writing, validating, and testing GraphQL queries.
Before you query the API, it’s recommended to run your queries through the visual interface to make sure they are correct and the data being returned is the data you expect.
You can use the following GraphiQL web interfaces to interact with the Enjin API: