-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGraphQL.cs
More file actions
44 lines (35 loc) · 1.16 KB
/
Copy pathGraphQL.cs
File metadata and controls
44 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
namespace GraphQL {
public class GraphQLClient {
private string url;
public GraphQLClient(string url) {
this.url = url;
}
[System.Serializable]
private class GraphQLQuery {
public string query;
public string variables;
public string operationName;
}
public UnityWebRequest Query(string query, string variables, string operationName) {
var fullQuery = new GraphQLQuery () {
query = query,
variables = variables,
operationName = operationName
};
string json = JsonUtility.ToJson (fullQuery);
//string sToken = "";
UnityWebRequest request = UnityWebRequest.Post(url, UnityWebRequest.kHttpVerbPOST);
byte[] payload = Encoding.UTF8.GetBytes (json);
UploadHandler data = new UploadHandlerRaw (payload);
request.uploadHandler = data;
request.SetRequestHeader ("Content-Type", "application/json");
//request.SetRequestHeader ("Authorization", "Bearer " + sToken);
return request;
}
}
}