/
Graphql.kt
86 lines (76 loc) 路 1.88 KB
/
Graphql.kt
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package io.appwrite.services
import android.net.Uri
import io.appwrite.Client
import io.appwrite.models.*
import io.appwrite.exceptions.AppwriteException
import io.appwrite.extensions.classOf
import okhttp3.Cookie
import java.io.File
/**
* The GraphQL API allows you to query and mutate your Appwrite server using GraphQL.
**/
class Graphql : Service {
public constructor (client: Client) : super(client) { }
/**
* GraphQL endpoint
*
* Execute a GraphQL mutation.
*
* @param query The query or queries to execute.
* @return [Any]
*/
suspend fun query(
query: Any,
): Any {
val apiPath = "/graphql"
val apiParams = mutableMapOf<String, Any?>(
"query" to query,
)
val apiHeaders = mutableMapOf(
"x-sdk-graphql" to "true",
"content-type" to "application/json",
)
val converter: (Any) -> Any = {
it
}
return client.call(
"POST",
apiPath,
apiHeaders,
apiParams,
responseType = Any::class.java,
converter,
)
}
/**
* GraphQL endpoint
*
* Execute a GraphQL mutation.
*
* @param query The query or queries to execute.
* @return [Any]
*/
suspend fun mutation(
query: Any,
): Any {
val apiPath = "/graphql/mutation"
val apiParams = mutableMapOf<String, Any?>(
"query" to query,
)
val apiHeaders = mutableMapOf(
"x-sdk-graphql" to "true",
"content-type" to "application/json",
)
val converter: (Any) -> Any = {
it
}
return client.call(
"POST",
apiPath,
apiHeaders,
apiParams,
responseType = Any::class.java,
converter,
)
}
}