Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Dec 18, 2020
1 parent 50db0ac commit b004985
Show file tree
Hide file tree
Showing 23 changed files with 605 additions and 2 deletions.
23 changes: 23 additions & 0 deletions codegen/src/main/kotlin/inline_fragments.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
query TestQuery {
animal {
age
... on WarmBlooded {
...BirdFragment
celsius: temperature
... on Pet {
name
}
}

... on Pet {
nick: name
}
}
}

fragment BirdFragment on Bird {
... on Eagle {
wingSize
}
feathers
}
25 changes: 25 additions & 0 deletions codegen/src/main/kotlin/inline_fragments.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package inline_fragments

class Data(val animal: Animal) {
interface Animal {
val age: Int
}

interface WarmBlooded {
val celsius: Float
interface Pet {
val name: String
}
}

interface Pet {
val nick: String
}
}

interface BirdFragment {
interface Eagle {
val wingSize: Float
}
val feathers: Int
}
16 changes: 16 additions & 0 deletions codegen/src/main/kotlin/merged_conditions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
query GetHero {
hero {
friend {
name
}
}
}

query GetHero {
hero {
friend @include(if: $condition) {
...droidFragment
id @include(if: $condition2)
}
}
}
1 change: 0 additions & 1 deletion codegen/src/main/kotlin/overlapping_fragments.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package overlapping_fragments


class Data(val hero: Hero) {
interface Hero {
val name: String
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/main/kotlin/polymorphic_fragment.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package polymorphic_fragment

class Data {
class HumanHero(override val name: String,
override val bestFriend: BestFriend
Expand Down
7 changes: 6 additions & 1 deletion json-scalar-type/src/test/kotlin/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import com.apollographql.apollo.api.CustomTypeAdapter
import com.apollographql.apollo.api.CustomTypeValue
import com.apollographql.apollo.coroutines.await
import com.apollographql.apollo.coroutines.toDeferred
import com.apollographql.apollo.coroutines.toFlow
import com.google.gson.internal.LinkedTreeMap
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -56,7 +60,8 @@ class MainTest {
.serverUrl("http://localhost:8080/graphql")
.build()

val response = apolloClient.query(GetProjectQuery()).toDeferred().await()
val channel = Channel<Unit>(capacity = Channel.UNLIMITED)
val response = apolloClient.query(GetProjectQuery()).watcher().toFlow().collect { }
println(response.data?.project)
delay(300000)
}
Expand Down
1 change: 1 addition & 0 deletions pets-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A JVM project that generates models and also has server code for testing
15 changes: 15 additions & 0 deletions pets-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
kotlin("jvm").version("1.4.0").apply(false)
id("com.apollographql.apollo").apply(false)
kotlin("plugin.spring").version("1.4.0").apply(false)
id("org.springframework.boot").version("2.3.3.RELEASE").apply(false)
id("net.mbonnin.one.eight").version("0.1")
}

subprojects {
repositories {
mavenCentral()
mavenLocal()
}
}

19 changes: 19 additions & 0 deletions pets-server/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
kotlin("jvm")
id("com.apollographql.apollo")
}

dependencies {
implementation("com.apollographql.apollo:apollo-runtime:${properties.get("apolloVersion")}")
implementation("com.apollographql.apollo:apollo-coroutines-support:${properties.get("apolloVersion")}")
implementation("com.apollographql.apollo:apollo-normalized-cache-sqlite:${properties.get("apolloVersion")}")

implementation("org.jetbrains.kotlin:kotlin-test")
implementation("com.squareup.okhttp3:logging-interceptor:4.8.1")
implementation("junit:junit:4.13")
implementation(project(":server"))
}

apollo {
generateKotlinModels.set(true)
}
18 changes: 18 additions & 0 deletions pets-server/client/src/main/graphql/com/example/operations.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
query getContent(
$vendors: [Int!]!,
$tags_filter_1: [Int!]!,
$tags_filter_2: [Int!]!
) {
content(
where:{
state: { _eq: "toto", numberInput: 0 },
vendor_id: {_in: $vendors},
_and : [
{ recipe_tags : { tag_id: {_in: $tags_filter_1}}},
{ recipe_tags : { tag_id: {_in: $tags_filter_2}}}
]
}
) {
id
}
}
34 changes: 34 additions & 0 deletions pets-server/client/src/main/graphql/com/example/schema.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
interface Collection {
items: [Item!]!
}

interface Item {
title: String!
}

type ParticularCollection implements Collection {
items: [Item!]!
}

type ParticularItem implements Item {
image: String!
title: String!
}

type Query {
collections: [Collection!]!
item: [Item!]!
}

type RegularCollection implements Collection {
items: [Item!]!
}

type RegularItem implements Item {
title: String!
}

schema {
subscription: subscription
query: Query
}
48 changes: 48 additions & 0 deletions pets-server/client/src/test/kotlin/MainTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.cache.normalized.NormalizedCache
import com.apollographql.apollo.cache.normalized.lru.EvictionPolicy
import com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory
import com.apollographql.apollo.coroutines.await
import com.example.GetContentQuery
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.junit.Test
import server.runServer

class MainTest {

@Test
fun test() {
val applicationContext = runServer()

runBlocking {
val apolloClient = ApolloClient.builder()
.okHttpClient(OkHttpClient.Builder().addInterceptor(
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
).build())
.normalizedCache(LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION))
.serverUrl("http://localhost:8080/graphql")
.build()

apolloClient.query(GetContentQuery(listOf(0), listOf(1), listOf(2)))
.await()
.let {
println("got ${it.data} (fromCache: ${it.fromCache})")
}

println(NormalizedCache.prettifyDump(apolloClient.apolloStore.normalizedCache().dump()))
apolloClient.query(GetContentQuery(listOf(0), listOf(1), listOf(3)))
.await()
.let {
println("got ${it.data} (fromCache: ${it.fromCache})")
}

println(NormalizedCache.prettifyDump(apolloClient.apolloStore.normalizedCache().dump()))
}
applicationContext.close()

}
}
1 change: 1 addition & 0 deletions pets-server/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apolloVersion=2.4.2
Binary file added pets-server/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions pets-server/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit b004985

Please sign in to comment.