-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a747e3d
commit 8fbec9d
Showing
22 changed files
with
282 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
6 changes: 6 additions & 0 deletions
6
...erator/src/test/data/generator/include_skip_directives/IncludeSkipDirectivesQuery.graphql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query IncludeSkipDirectivesQuery($includeCondition: Boolean!, $skipCondition: Boolean!) { | ||
enumQuery @include(if: $includeCondition) | ||
scalarQuery @skip(if: $skipCondition) { | ||
count | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...t-generator/src/test/data/generator/include_skip_directives/IncludeSkipDirectivesQuery.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.expediagroup.graphql.generated | ||
|
||
import com.expediagroup.graphql.client.Generated | ||
import com.expediagroup.graphql.client.types.GraphQLClientRequest | ||
import com.expediagroup.graphql.generated.enums.CustomEnum | ||
import com.expediagroup.graphql.generated.includeskipdirectivesquery.ScalarWrapper | ||
import kotlin.Boolean | ||
import kotlin.String | ||
import kotlin.reflect.KClass | ||
|
||
public const val INCLUDE_SKIP_DIRECTIVES_QUERY: String = | ||
"query IncludeSkipDirectivesQuery(${'$'}includeCondition: Boolean!, ${'$'}skipCondition: Boolean!) {\n enumQuery @include(if: ${'$'}includeCondition)\n scalarQuery @skip(if: ${'$'}skipCondition) {\n count\n }\n}" | ||
|
||
@Generated | ||
public class IncludeSkipDirectivesQuery( | ||
public override val variables: IncludeSkipDirectivesQuery.Variables | ||
) : GraphQLClientRequest<IncludeSkipDirectivesQuery.Result> { | ||
public override val query: String = INCLUDE_SKIP_DIRECTIVES_QUERY | ||
|
||
public override val operationName: String = "IncludeSkipDirectivesQuery" | ||
|
||
public override fun responseType(): KClass<IncludeSkipDirectivesQuery.Result> = | ||
IncludeSkipDirectivesQuery.Result::class | ||
|
||
@Generated | ||
public data class Variables( | ||
public val includeCondition: Boolean, | ||
public val skipCondition: Boolean | ||
) | ||
|
||
@Generated | ||
public data class Result( | ||
/** | ||
* Query that returns enum value | ||
*/ | ||
public val enumQuery: CustomEnum? = null, | ||
/** | ||
* Query that returns wrapper object with all supported scalar types | ||
*/ | ||
public val scalarQuery: ScalarWrapper? = null | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
...tlin-client-generator/src/test/data/generator/include_skip_directives/enums/CustomEnum.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.expediagroup.graphql.generated.enums | ||
|
||
import com.expediagroup.graphql.client.Generated | ||
import com.fasterxml.jackson.`annotation`.JsonEnumDefaultValue | ||
import com.fasterxml.jackson.`annotation`.JsonProperty | ||
import kotlin.Deprecated | ||
|
||
/** | ||
* Custom enum description | ||
*/ | ||
@Generated | ||
public enum class CustomEnum { | ||
/** | ||
* First enum value | ||
*/ | ||
ONE, | ||
/** | ||
* Third enum value | ||
*/ | ||
@Deprecated(message = "only goes up to two") | ||
THREE, | ||
/** | ||
* Second enum value | ||
*/ | ||
TWO, | ||
/** | ||
* Lowercase enum value | ||
*/ | ||
@JsonProperty("four") | ||
FOUR, | ||
/** | ||
* This is a default enum value that will be used when attempting to deserialize unknown value. | ||
*/ | ||
@JsonEnumDefaultValue | ||
__UNKNOWN_VALUE, | ||
} |
15 changes: 15 additions & 0 deletions
15
...c/test/data/generator/include_skip_directives/includeskipdirectivesquery/ScalarWrapper.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.expediagroup.graphql.generated.includeskipdirectivesquery | ||
|
||
import com.expediagroup.graphql.client.Generated | ||
import kotlin.Int | ||
|
||
/** | ||
* Wrapper that holds all supported scalar types | ||
*/ | ||
@Generated | ||
public data class ScalarWrapper( | ||
/** | ||
* A signed 32-bit nullable integer value | ||
*/ | ||
public val count: Int? = null | ||
) |
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
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
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
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
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
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
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
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
73 changes: 73 additions & 0 deletions
73
...aphql-kotlin-gradle-plugin/src/integration/client-generator/skip_include/build.gradle.kts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateSDLTask | ||
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateTestClientTask | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal { | ||
content { | ||
includeGroup("com.expediagroup") | ||
} | ||
} | ||
} | ||
|
||
val graphQLKotlinVersion = System.getenv("GRAPHQL_KOTLIN_VERSION") ?: "5.0.0-SNAPSHOT" | ||
dependencies { | ||
classpath("com.expediagroup:graphql-kotlin-gradle-plugin:$graphQLKotlinVersion") | ||
} | ||
} | ||
|
||
plugins { | ||
id("org.springframework.boot") version "2.5.5" | ||
kotlin("jvm") version "1.5.31" | ||
kotlin("plugin.spring") version "1.5.31" | ||
} | ||
|
||
apply(plugin = "com.expediagroup.graphql") | ||
|
||
group = "com.expediagroup" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal { | ||
content { | ||
includeGroup("com.expediagroup") | ||
} | ||
} | ||
} | ||
|
||
val graphQLKotlinVersion = System.getenv("GRAPHQL_KOTLIN_VERSION") ?: "5.0.0-SNAPSHOT" | ||
val icuVersion = System.getenv("ICU_VERSION") ?: "69.1" | ||
val junitVersion = System.getenv("JUNIT_VERSION") ?: "5.7.2" | ||
val kotlinVersion = System.getenv("KOTLIN_VERSION") ?: "1.5.31" | ||
val springBootVersion = System.getenv("SPRINGBOOT_VERSION") ?: "2.5.5" | ||
dependencies { | ||
implementation("com.expediagroup:graphql-kotlin-hooks-provider:$graphQLKotlinVersion") | ||
implementation("com.expediagroup:graphql-kotlin-spring-client:$graphQLKotlinVersion") | ||
implementation("com.expediagroup:graphql-kotlin-spring-server:$graphQLKotlinVersion") | ||
implementation("com.ibm.icu:icu4j:$icuVersion") | ||
testImplementation(kotlin("test-junit5", kotlinVersion)) | ||
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") | ||
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "11" | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
val graphqlGenerateSDL by tasks.getting(GraphQLGenerateSDLTask::class) { | ||
packages.set(listOf("com.expediagroup.directives")) | ||
} | ||
val graphqlGenerateTestClient by tasks.getting(GraphQLGenerateTestClientTask::class) { | ||
packageName.set("com.expediagroup.directives.generated") | ||
schemaFile.set(graphqlGenerateSDL.schemaFile) | ||
} |
1 change: 1 addition & 0 deletions
1
...ql-kotlin-gradle-plugin/src/integration/client-generator/skip_include/settings.gradle.kts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = "include-skip-test" |
11 changes: 11 additions & 0 deletions
11
.../client-generator/skip_include/src/main/kotlin/com/expediagroup/directives/Application.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.expediagroup.directives | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class Application | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<Application>(*args) | ||
} |
11 changes: 11 additions & 0 deletions
11
.../client-generator/skip_include/src/main/kotlin/com/expediagroup/directives/SimpleQuery.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.expediagroup.directives | ||
|
||
import com.expediagroup.graphql.server.operations.Query | ||
import org.springframework.stereotype.Component | ||
import java.util.UUID | ||
|
||
@Component | ||
class SimpleQuery : Query { | ||
|
||
fun simpleQuery(): String = UUID.randomUUID().toString() | ||
} |
3 changes: 3 additions & 0 deletions
3
...e-plugin/src/integration/client-generator/skip_include/src/main/resources/application.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
graphql: | ||
packages: | ||
- "com.expediagroup.directives" |
52 changes: 52 additions & 0 deletions
52
...ent-generator/skip_include/src/test/kotlin/com/expediagroup/directives/ApplicationTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.expediagroup.directives | ||
|
||
import com.expediagroup.directives.generated.IncludeSkipQuery | ||
import com.expediagroup.graphql.client.spring.GraphQLWebClient | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.web.server.LocalServerPort | ||
import java.util.UUID | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertNull | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class ApplicationTest(@LocalServerPort private val port: Int) { | ||
|
||
@Test | ||
fun `verify include and skip directives are honored by client`(): Unit = runBlocking { | ||
val client = GraphQLWebClient(url = "http://localhost:$port/graphql") | ||
|
||
val skippedQuery = IncludeSkipQuery(variables = IncludeSkipQuery.Variables( | ||
includeCondition = false, | ||
skipCondition = true | ||
)) | ||
|
||
val response = client.execute(skippedQuery) | ||
val simpleResponse = response.data?.simpleQuery | ||
assertNotNull(simpleResponse) | ||
assertNotNull(UUID.fromString(simpleResponse)) | ||
|
||
val included = response.data?.included | ||
assertNull(included) | ||
val skipped = response.data?.skipped | ||
assertNull(skipped) | ||
|
||
val includeQuery = IncludeSkipQuery(variables = IncludeSkipQuery.Variables( | ||
includeCondition = true, | ||
skipCondition = false | ||
)) | ||
|
||
val nonNullResponse = client.execute(includeQuery) | ||
val simpleResponseNonNull = nonNullResponse.data?.simpleQuery | ||
assertNotNull(simpleResponseNonNull) | ||
assertNotNull(UUID.fromString(simpleResponseNonNull)) | ||
|
||
val includedNonNull = nonNullResponse.data?.included | ||
assertNotNull(includedNonNull) | ||
assertNotNull(UUID.fromString(includedNonNull)) | ||
val skippedNonNull = nonNullResponse.data?.skipped | ||
assertNotNull(skippedNonNull) | ||
assertNotNull(UUID.fromString(skippedNonNull)) | ||
} | ||
} |
Oops, something went wrong.