Links

Learn GraphQL

Discover more about GraphQL.

What is GraphQL?

GraphQL is an advanced query language that enables you to specify the structure of your queries and request only the necessary data.
With GraphQL, you can access the properties of multiple resources and follow references between them in a seamless manner. In contrast to conventional REST APIs, GraphQL APIs retrieve all the data required for your application with just one request instead of multiple URLs.
Operations
Query: GraphQL queries are used to perform READ operations and do not modify any data.
Mutation: Mutations are used to MODIFY (mutate) data and perform all operations other than reading in GraphQL.
Types
Types define the structure of the data that can be queried from the API, comprising a set of fields.
# Operations
query {
}
mutation {
}
# Types
Account : {
publicKey: String
account: String
}

Fields

Fields are used to ask for specific object properties. Most Queries and Mutations return a specific GraphQL Type which defines which properties you can return data for. For example in the codeblock below we ask the GetToken query to return the metadata field from the database.
Some Queries and Mutations will return Scalar types which are things like boolean, int and string and have no other named properties so return their value directly.
# This query returns a Token type.
query {
GetToken(collectionId: "2000", tokenId:{ integer: 1 }) {
metadata
}
}
# This mutation directly returns a Boolean value.
mutation {
CreateWallet(externalId:"PlayerOne")
}

Arguments

You can pass data into an operation by using arguments, these are set in parenthesis after the operation name. Most Queries and Mutations define a set of input data you can use, for example in the GetToken query above you can pass in a collectionId and a tokenId. Sometimes arguments will be required, sometimes they will be optional, and some operations may not take any arguments at all. The API will tell you if you try to run an operation without a required argument.

How does GraphQL Interact with the Enjin Platform?

In the context of the Enjin Platform, by using GraphQL, developers are able to create, mint, transfer, and fetch information on FTs and NFTs created using the platform without needing to interact with any back-end information from the blockchain.
As an example, we are going to display one Query and one Mutation that is used by the Enjin Platform.
Query - with this specific query, we are able to perform a READ operation on the Blockchain in order to retrieve information pertaining to a specific Collection, all queries must contain an operation and fields, most also require arguments.
query GetCollection {
GetCollection(collectionId: "1578") {
collectionId
forceSingleMint
frozen
maxTokenCount
owner {
account {
address
}
}
}
}
Response - In the response field, we can see that the GetCollection query returned the Id of the collection, the account owner, and a few other pieces of information about the collection.
{
"data": {
"GetCollection": {
"collectionId": "1578",
"forceSingleMint": false,
"frozen": false,
"maxTokenCount": 15,
"owner": {
"account": {
"address": "rf7kWrgvWetRimbcJcZweUoePpBKNnCnpxXfDNUUC3RYFYR6p"
}
}
}
}
}
Mutation - Just like in queries, if the mutation field returns a GraphQL Type, you can ask for its fields. This can be useful for fetching the new state of an object after an update. Let's look at a simple example of a mutation that returns a Transaction Type for creating a collection.
mutation {
CreateCollection(
explicitRoyaltyCurrencies: {collectionId: "2057", tokenId: {erc1155: {tokenId: "1", index: "1"}}}
mintPolicy: {forceSingleMint: true, maxTokenCount: "1", maxTokenSupply: "1"}
) {
id
idempotencyKey
method
result
}
}
Response - With this mutation, we are sending a request to the platform to create a collection and setting the explicitRoyaltyCurrencies to a specific a token using the ERC1155 encoder. In the return data we get details about the transaction that will be broadcast to the blockchain.
{
"data": {
"CreateCollection": {
"id": 1,
"idempotencyKey": "e876a6f7-489e-40e9-85d3-fd3e2671ba56",
"method": "CreateCollection",
"result": "PENDING"
}
}
}
For further reference on how GraphQL works, you can also refer to their documentation here.

GraphiQL Desktop App

You can also download the desktop version of GraphiQL to interact with the Enjin Platform API.
Download for macOS: If you have Homebrew installed on macOS:
brew install --cask graphiql
Alternately, download the binary from the Releases tab.
Download for Linux: The graphiql-app uses the AppImage format for its Linux version. You download it from the Electron app directory (click the "Download for Linux"-button) or from the Releases tab.
Either way, you will get a .AppImage binary. Put it in a safe place and make it executable:
chmod +x graphiql-app-0.7.2-x86_64.AppImage
Then simply execute the app. It will ask whether to add shortcuts to your desktop and menus for easy access in the future.

Getting started

  • Branch and/or clone the repo locally.
  • cd into it
  • install all the require packages: npm i
  • build the project: npm run build
  • start the project: npm start

Postman API Platform Desktop App

You can also download the desktop version of Postman to interact with the Enjin Platform API.
Download for macOS (Intel Chip): https://dl.pstmn.io/download/latest/osx_64
Download for macOS (Apple Chip): https://dl.pstmn.io/download/latest/osx_arm64
© 2023 Enjin Pte. Ltd.