Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3b74bf

Browse files
authored
fix: use enum value in GraphQLEnumValueDefinition (#2112)
### 📝 DescriptionAttempting to output an enum value with a custom `@GraphQLName`annotation will currently result in something like:> SerializationError{path=[enumOutputs, 3],exception=graphql.schema.CoercingSerializeException: Invalid input forenum 'MyTestEnum'. Unknown value 'FOUR'}This PR changes the GraphQLEnumValueDefinition `value` to be the enumentry itself rather than the graphql name, which allows graphql-java tocorrectly resolve the name from the definition.### 🔗 Related Issues
1 parent7412ed8 commite3b74bf

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

‎generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/types/generateEnum.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private fun getEnumValueDefinition(generator: SchemaGenerator, enum: Enum<*>, kC
5656
validateGraphQLEnumValue(name, kClass)
5757

5858
valueBuilder.name(name)
59-
valueBuilder.value(name)
59+
valueBuilder.value(enum)
6060

6161
generateEnumValueDirectives(generator, valueField, kClass.getSimpleName()).forEach {
6262
valueBuilder.withAppliedDirective(it)

‎generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateEnumTest.kt‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ class GenerateEnumTest : TypeTestHelper() {
6868
val actual= generateEnum(generator,MyTestEnum::class)
6969
assertEquals(expected=4, actual= actual.values.size)
7070
assertEquals(expected="MyTestEnum", actual= actual.name)
71-
assertEquals(expected="ONE", actual= actual.values[0].value)
72-
assertEquals(expected="TWO", actual= actual.values[1].value)
73-
assertEquals(expected="THREE", actual= actual.values[2].value)
74-
assertEquals(expected="customFour", actual= actual.values[3].value)
71+
assertEquals(expected="ONE", actual= actual.values[0].name)
72+
assertEquals(expected=MyTestEnum.ONE, actual= actual.values[0].value)
73+
assertEquals(expected="TWO", actual= actual.values[1].name)
74+
assertEquals(expected=MyTestEnum.TWO, actual= actual.values[1].value)
75+
assertEquals(expected="THREE", actual= actual.values[2].name)
76+
assertEquals(expected=MyTestEnum.THREE, actual= actual.values[2].value)
77+
assertEquals(expected="customFour", actual= actual.values[3].name)
78+
assertEquals(expected=MyTestEnum.FOUR, actual= actual.values[3].value)
7579
}
7680

7781
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
packagecom.expediagroup.graphql.generator.test.integration
18+
19+
importcom.expediagroup.graphql.generator.TopLevelObject
20+
importcom.expediagroup.graphql.generator.internal.types.GenerateEnumTest
21+
importcom.expediagroup.graphql.generator.testSchemaConfig
22+
importcom.expediagroup.graphql.generator.toSchema
23+
importgraphql.GraphQL
24+
importorg.junit.jupiter.api.Test
25+
importkotlin.test.assertEquals
26+
27+
@Suppress(
28+
"Detekt.UnusedPrivateMember",
29+
)
30+
classCustomEnumExecutionTest {
31+
32+
privateval schema= toSchema(
33+
queries=listOf(TopLevelObject(QueryObject())),
34+
config= testSchemaConfig()
35+
)
36+
privateval graphQL:GraphQL=GraphQL.newGraphQL(schema).build()
37+
38+
@Test
39+
fun`a custom enum name can be used as output`() {
40+
val result= graphQL.execute("{ enumOutputs }")
41+
val data:Map<String,List<String>>?= result.getData()
42+
43+
assertEquals(emptyList(), result.errors)
44+
assertEquals(listOf("ONE","TWO","THREE","customFour"), data?.get("enumOutputs"))
45+
}
46+
47+
@Test
48+
fun`an implicit enum name be used as input`() {
49+
val result= graphQL.execute("{ enumInput(value: THREE) }")
50+
val data:Map<String,String>?= result.getData()
51+
52+
assertEquals(emptyList(), result.errors)
53+
assertEquals("hello, THREE", data?.get("enumInput"))
54+
}
55+
56+
@Test
57+
fun`a custom enum name be used as input`() {
58+
val result= graphQL.execute("{ enumInput(value: customFour) }")
59+
val data:Map<String,String>?= result.getData()
60+
61+
assertEquals(emptyList(), result.errors)
62+
assertEquals("hello, FOUR", data?.get("enumInput"))
63+
}
64+
65+
classQueryObject {
66+
funenumOutputs():List<GenerateEnumTest.MyTestEnum>=GenerateEnumTest.MyTestEnum.entries
67+
funenumInput(value:GenerateEnumTest.MyTestEnum)="hello,$value"
68+
}
69+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp