我在这里使用了一个在线示例应用编程接口:https://api.spacex.land/graphql/。我正在使用Unity中的GraphQL来查询“用户”的数据。我能够创建查询并接收所有属性,如ID、名称等。不幸的是,我根本无法接收这些属性的详细信息。下面给出的两个函数都抛出了一个错误Unknown argument
。我在这里做错了什么?
using GraphQlClient.Core;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class GetStationDetails : MonoBehaviour {
public GraphApi spacexGraph;
public string Name = "Prakash";
void Update () {
if (Input.GetKeyDown (KeyCode.D)) {
GetEnteredDetails ();
}
if (Input.GetKeyDown (KeyCode.F)) {
GetAllDetails ();
}
}
public async void GetEnteredDetails () {
GraphApi.Query query = spacexGraph.GetQueryByName ("GetAllData", GraphApi.Query.Type.Query);
query.SetArgs (new { name = Name });
UnityWebRequest request = await spacexGraph.Post (query);
Debug.Log ("Received: " + request.downloadHandler.text);
}
public async void GetAllDetails () {
GraphApi.Query query = spacexGraph.GetQueryByName ("GetAllData", GraphApi.Query.Type.Query);
query.SetArgs (new { first = 6 });
UnityWebRequest request = await spacexGraph.Post (query);
Debug.Log ("Received: " + request.downloadHandler.text);
}
}
发布于 2020-09-29 12:24:32
问题是您试图构建的查询不正确。而不是使用:
query.SetArgs (new { name = Name });
您想要使用
query.SetArgs (new { where = new {name = new{_in = Name}} });
这应该会创建查询:
query GetAllData{
users(where:{name:{_in: "Parkash"}}){
id
name
rocket
timestamp
}
}
You can also change _in to e.g "_like", if you want to get any name that partly matches what you've entered, or any other similar SQL keyword
https://stackoverflow.com/questions/64117552
复制