Last active
January 16, 2019 04:05
-
-
Save yshrsmz/4c8112dcfc00b195bef016ef27a6cd7d to your computer and use it in GitHub Desktop.
kgql - GraphQL Wrapper generator for Kotlin MPP, https://github.com/yshrsmz/kgql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query User( | |
$login: String!, | |
$name: Int, | |
$id: String = "", | |
$company: String = null, | |
$foo: Float, | |
$logins: [String]) { | |
user(login: $login) { | |
id | |
login | |
bio | |
avatarUrl | |
company | |
createdAt | |
} | |
} | |
mutation withArbitraryType($user: UserProfile) { | |
user(login: $login) { | |
id | |
login | |
bio | |
avatarUrl | |
company | |
createdAt | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample | |
import com.codingfeline.kgql.core.KgqlRequestBody | |
import com.sample.data.UserProfile | |
import kotlin.Float | |
import kotlin.Int | |
import kotlin.String | |
import kotlin.collections.List | |
import kotlinx.serialization.KSerializer | |
import kotlinx.serialization.Serializable | |
object QueryWithParamDocumentWrapper { | |
private val document: String = """ | |
|query User( | |
| ${'$'}login: String!, | |
| ${'$'}name: Int, | |
| ${'$'}id: String = "", | |
| ${'$'}company: String = null, | |
| ${'$'}foo: Float, | |
| ${'$'}logins: [String]) { | |
| user(login: ${'$'}login) { | |
| id | |
| login | |
| bio | |
| avatarUrl | |
| company | |
| createdAt | |
| } | |
|} | |
| | |
|mutation withArbitraryType(${'$'}user: UserProfile) { | |
| user(login: ${'$'}login) { | |
| id | |
| login | |
| bio | |
| avatarUrl | |
| company | |
| createdAt | |
| } | |
|} | |
|""".trimMargin() | |
object UserQuery { | |
fun query(variables: Variables): KgqlRequestBody<Variables> = | |
KgqlRequestBody<Variables>(operationName="User", query=document, | |
variables=variables) | |
fun serializer(): KSerializer<KgqlRequestBody<Variables>> = | |
KgqlRequestBody.serializer(com.sample.QueryWithParamDocumentWrapper.UserQuery.Variables.serializer()) | |
@Serializable | |
data class Variables( | |
val login: String, | |
val name: Int?, | |
val id: String?, | |
val company: String?, | |
val foo: Float?, | |
val logins: List<String?>? | |
) | |
} | |
object WithArbitraryTypeMutation { | |
fun mutation(variables: Variables): KgqlRequestBody<Variables> = | |
KgqlRequestBody<Variables>(operationName="withArbitraryType", query=document, | |
variables=variables) | |
fun serializer(): KSerializer<KgqlRequestBody<Variables>> = | |
KgqlRequestBody.serializer(com.sample.QueryWithParamDocumentWrapper.WithArbitraryTypeMutation.Variables.serializer()) | |
@Serializable | |
data class Variables(val user: UserProfile?) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment