首页 > 解决方案 > 如何在 Unity3D proyecto26 库中使用 graphql?

问题描述

我在我的 API 上实现了 GraphQL,但是我不知道如何在我正在使用的库上执行它。

using UnityEngine;
using UnityEditor;
using Models;
using Proyecto26;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.UI;

public class AuthController : MonoBehaviour {
  private readonly string basePath = "http://localhost:1337";
  public void Get(){
        currentRequest = new RequestHelper {
            Uri = basePath + "/graphql",
            Method = "GET",
            BodyString = "query {users {_id username email}}" //Use it instead of 'Body' to serialize using other tools
        };

        RestClient.Get<Auth>(currentRequest).Then(
            res => {

                string encodedString =JsonUtility.ToJson(res, true);                
                JSONObject jar = new JSONObject(encodedString);
                Debug.Log(jar);
            });

    }
}

它只是返回错误。它可能是“BodyString”,但我不太确定。因为这是我第一次在 Unity 项目中使用GraphQl 。请帮助我如何使用Proyecto26正确查询。

标签: unity3dgraphql

解决方案


我已经通过使用这个库Gazuntype/graphQL解决了这个问题,现在在我的项目中使用 GraphQL 更方便。这解决了我的问题。它还使用 simpleJSON 来反序列化响应。


推荐阅读