With GraphQL for Unity you can execute GraphQL Queries in a Unity way with GameObjects. But with the asset you can also execute queries in Unity with C# code.
Here is a simple example:
public GraphQL Connection;
public void ScriptQuery()
{
var query = "query($Token: String!) { doit($Token) { result } } ";
var args = new JObject
{
{ "Token", "123" }
};
Connection.ExecuteQuery(query, args, (result) =>
{
Debug.Log(result.Result.ToString());
});
}
Link the Connection variable to your GraphQL GameObject where the connection is set.
Note: the result callback function is called asynchronous and it is not executed in the Game-loop.
A bit more complex example how the args variable could look like. This is just an example how you can create a JSON object in C# in a convenient way.
JObject args = new JObject
{
["UpdateList"] = new JArray
{
new JObject
{
["id"] = 28,
["updateAction"] = "EDIT",
["status"] = "Present"
},
new JObject
{
["id"] = 29,
["updateAction"] = "EDIT",
["status"] = "Absent"
},
new JObject
{
["id"] = 30,
["updateAction"] = "EDIT",
["status"] = "Present"
}
}
};