Rawrshak Documentation
  • Rawrshak
  • Rawrshak Platform
    • What is the Rawrshak Platform?
    • Platform Overview
    • Rawrshak Ecosystem
    • Networks
    • Litepapers
    • Community Channels
    • Partnerships & Integrations
  • Tutorials
    • Gamer
      • Setup
        • Metamask Wallet
        • Adding Optimism Kovan Network
        • Funding Testnet Wallet
      • Demo
    • Developer
      • Setup
        • Arweave Wallet
          • ArDrive Account
        • Pinata
        • Unity
      • Demo
      • Unity
        • Loading the Rawrshak Tools
        • Loading the Rawrshak SDK
        • 3D Static Object In-game Framework
        • Packaging an Asset
          • Static 3D Object Asset
          • Audio Asset
        • Custom Subgraph Query
        • Prefabs
          • Wallet
          • Subgraph
          • Ethereum Blockchain Query
          • Rawrshak Asset
      • Rawrshak Dapp
        • Deploy a Content Contract
        • Upload Data to Arweave
        • Deploying a Meta Asset
          • Image Meta Asset
          • Audio Meta Asset
          • Static 3D Object Meta Asset
        • Updating a Meta Asset's Metadata
        • Minting a Meta Asset
        • Selling a Meta Asset
      • 🚧Custom Subgraphs
    • Unity Asset Viewer
  • Gamers
    • Gamer Decentralized Applications
    • Gaming Marketplace
    • Meta Assets
    • Supported Wallets
  • Developers
    • Smart Contracts
      • Content Contracts
        • Content
        • Content Manager
        • Content Storage
        • Content Factory
      • Exchange Contracts
        • Exchange
        • Orderbook
        • Execution Manager
        • Royalty Manager
        • Erc20Escrow
        • NftEscrow
      • Libraries
        • LibAsset
        • LibOrder
      • Utilities
        • Address Resolver
    • Meta Asset Framework
      • Asset Metadata
      • Asset Types
        • Text Assets
        • Image Assets
        • Audio Assets
        • Static 3D Objects
    • Game Engines
      • Unity Game Engine
        • Unity SDK
        • Unity Tools
      • Unreal Game Engine
      • Godot Game Engine
    • Developer Decentralized Applications
    • Rawrshak Subgraphs
      • Entities
        • Content Subgraph
        • Exchange Subgraph
  • Governance
    • RAWR Token
      • Tokenomics
      • Contract Addresses
    • Rawrshak DAO
Powered by GitBook
On this page
  • Requirements
  • Tutorial
  1. Tutorials
  2. Developer
  3. Unity

Custom Subgraph Query

PreviousAudio AssetNextPrefabs

Last updated 3 years ago

Requirements

  • Familiarity with GraphQL queries and The Graph queries (see )

  • A Unity project with the Rawrshak SDK installed

Our examples are only for Rawrshak's Content and Exchange subgraphs. A developer can create custom queries for our subgraphs.

A developer can also retrofit this tutorial for any GraphQL source or any subgraph.

Tutorial

1. Create a folder for custom graphql queries

2. Inside that folder, create a "Resources" folder and a "Scripts" folder

3. In the Resources folder, create a text file that contains the GraphQL query

Filename: GetAssetName.txt

query GetAssetName {{
    asset ( id: "{0}-{1}" ) {{
        name
    }}
}}

Notes:

  • GraphQL query syntax "{" and "}" must be replaced with "{{" and "}}"

  • Query parameters are indexed. {0} and {1} indicate the first parameter and second parameter for the query.

4. Create Query Script

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Numerics;
using UnityEngine;
using UnityEngine.Networking;
using GraphQlClient.Core;
using Rawrshak;

public class GetAssetName: QueryBase
{
    public static async Task<ReturnData> Fetch(string contractAddress, string tokenId) {
        // Load query if this is the first Fetch
        string query = LoadQuery("GetAssetName"); // Where GetAssetName is the filename.
        
        // Load the query parameters
        string queryWithArgs = String.Format(query, contractAddress.ToLower(), tokenId);

        // Post query
        string returnData = await PostAsync(Subgraph.Instance.contentsSubgraphUri, queryWithArgs);

        // Parse data
        return JsonUtility.FromJson<ReturnData>(returnData);
    }

    [Serializable]
    public class ReturnData
    {
        public DataObject data;
    }

    [Serializable]
    public class DataObject 
    {
        public AssetData asset;
    }

    [Serializable]
    public class AssetData 
    {
        public string name;
    }
}

Notes:

  • This script should inherit from QueryBase

  • queryWithArgs format string should match the number of inputs in the GetAssetName.txt

  • Subgraph object is in the Rawrshak SDK. If pointing to a different subgraph, replace this with the correct subgraph source uri

  • The ReturnData object should match the serializable json object returned by the query

5. Use the Custom Query

To use the query:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetAssetInfoScript : MonoBehaviour
{
    // Input
    public string contentContractAddress;
    public int tokenId;

    // Return Value
    public GetAssetName.ReturnData data;

    // Start is called before the first frame update
    async void Start()
    {
        // Test Query
        data = await GetAssetName.Fetch(contentContractAddress, tokenId.ToString());
    }
}

Please check out the and Pages for more info

https://thegraph.com/docs/en/developer/graphql-api/
Content
Exchange