Skip to content

Commit 99847f3

Browse files
authored
[plugin] update generated GraphQL client execute query method (#711)
Update generated client query method from `<operationName>` to simple `execute`, e.g. given operation name `HelloWorldQuery` we would end up generating it as `HelloWorldQuery.helloWorldQuery`, instead we will now generate it as `HelloWorldQuery.execute`.
1 parent 1ce72a6 commit 99847f3

File tree

11 files changed

+22
-24
lines changed

11 files changed

+22
-24
lines changed

plugins/graphql-kotlin-gradle-plugin/src/test/kotlin/com/expediagroup/graphql/plugin/gradle/GraphQLGradlePluginIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class GraphQLGradlePluginIT {
132132
// unsure if there is a better way - correct values are set from Gradle build
133133
// when running directly from IDE you will need to manually update those to correct values
134134

135-
val gqlKotlinVersion = System.getProperty("graphQLKotlinVersion") ?: "2.0.0-SNAPSHOT"
135+
val gqlKotlinVersion = System.getProperty("graphQLKotlinVersion") ?: "3.0.0-SNAPSHOT"
136136
val kotlinVersion = System.getProperty("kotlinVersion") ?: "1.3.71"
137137
val buildFileContents = """
138138
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -199,7 +199,7 @@ class GraphQLGradlePluginIT {
199199
200200
val variables = JUnitQuery.Variables(JUnitQuery.SimpleArgumentInput(min = null, max = null, newName = "blah"))
201201
runBlocking {
202-
val result = query.jUnitQuery(variables)
202+
val result = query.execute(variables)
203203
val data = result.data
204204
assert(data != null)
205205
assert(JUnitQuery.CustomEnum.ONE == data?.enumQuery)

plugins/graphql-kotlin-maven-plugin/src/integration/complete-setup/src/test/kotlin/com/expediagroup/graphql/plugin/maven/GraphQLMavenPluginTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GraphQLMavenPluginTest {
5353
val variables = ExampleQuery.Variables(simpleCriteria = ExampleQuery.SimpleArgumentInput(newName = "whatever", min = null, max = null))
5454
assertDoesNotThrow {
5555
runBlocking {
56-
val response = query.exampleQuery(variables = variables)
56+
val response = query.execute(variables = variables)
5757
assertTrue(response.errors == null)
5858
val data = response.data
5959
assertNotNull(data)

plugins/graphql-kotlin-plugin-core/src/main/kotlin/com/expediagroup/graphql/plugin/generator/GraphQLClientGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class GraphQLClientGenerator(
7575
val kotlinResultTypeName = ClassName(context.packageName, "${context.rootType}.${graphQLResultTypeSpec.name}")
7676

7777
val operationTypeSpec = TypeSpec.classBuilder(operationTypeName)
78-
val funSpec = FunSpec.builder(operationName.decapitalize())
78+
val funSpec = FunSpec.builder("execute")
7979
.returns(ClassName(LIBRARY_PACKAGE, "GraphQLResult").parameterizedBy(kotlinResultTypeName))
8080
.addModifiers(KModifier.SUSPEND)
8181
val variableCode = if (variableType != null) {

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLCustomScalarTypeAliasIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class GenerateGraphQLCustomScalarTypeAliasIT {
4141
class ScalarAliasTestQuery(
4242
private val graphQLClient: GraphQLClient
4343
) {
44-
suspend fun scalarAliasTestQuery(): GraphQLResult<ScalarAliasTestQuery.ScalarAliasTestQueryResult>
45-
= graphQLClient.execute(SCALAR_ALIAS_TEST_QUERY, "ScalarAliasTestQuery", null)
44+
suspend fun execute(): GraphQLResult<ScalarAliasTestQuery.ScalarAliasTestQueryResult> =
45+
graphQLClient.execute(SCALAR_ALIAS_TEST_QUERY, "ScalarAliasTestQuery", null)
4646
4747
/**
4848
* Wrapper that holds all supported scalar types

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLCustomScalarTypeSpecIT.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class GenerateGraphQLCustomScalarTypeSpecIT {
4242
class CustomScalarTestQuery(
4343
private val graphQLClient: GraphQLClient
4444
) {
45-
suspend fun customScalarTestQuery():
46-
GraphQLResult<CustomScalarTestQuery.CustomScalarTestQueryResult> =
45+
suspend fun execute(): GraphQLResult<CustomScalarTestQuery.CustomScalarTestQueryResult> =
4746
graphQLClient.execute(CUSTOM_SCALAR_TEST_QUERY, "CustomScalarTestQuery", null)
4847
4948
/**

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLEnumTypeSpecIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GenerateGraphQLEnumTypeSpecIT {
3737
class EnumTestQuery(
3838
private val graphQLClient: GraphQLClient
3939
) {
40-
suspend fun enumTestQuery(): GraphQLResult<EnumTestQuery.EnumTestQueryResult> =
40+
suspend fun execute(): GraphQLResult<EnumTestQuery.EnumTestQueryResult> =
4141
graphQLClient.execute(ENUM_TEST_QUERY, "EnumTestQuery", null)
4242
4343
/**

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLInputObjectTypeSpecIT.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class GenerateGraphQLInputObjectTypeSpecIT {
3737
class InputObjectTestQuery(
3838
private val graphQLClient: GraphQLClient
3939
) {
40-
suspend fun inputObjectTestQuery(): GraphQLResult<InputObjectTestQuery.InputObjectTestQueryResult>
41-
= graphQLClient.execute(INPUT_OBJECT_TEST_QUERY, "InputObjectTestQuery", null)
40+
suspend fun execute(): GraphQLResult<InputObjectTestQuery.InputObjectTestQueryResult> =
41+
graphQLClient.execute(INPUT_OBJECT_TEST_QUERY, "InputObjectTestQuery", null)
4242
4343
data class InputObjectTestQueryResult(
4444
/**
@@ -73,7 +73,7 @@ class GenerateGraphQLInputObjectTypeSpecIT {
7373
class AliasTestQuery(
7474
private val graphQLClient: GraphQLClient
7575
) {
76-
suspend fun aliasTestQuery(): GraphQLResult<AliasTestQuery.AliasTestQueryResult> =
76+
suspend fun execute(): GraphQLResult<AliasTestQuery.AliasTestQueryResult> =
7777
graphQLClient.execute(ALIAS_TEST_QUERY, "AliasTestQuery", null)
7878
7979
data class AliasTestQueryResult(

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLInterfaceTypeSpecIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GenerateGraphQLInterfaceTypeSpecIT {
4545
class InterfaceWithInlineFragmentsTestQuery(
4646
private val graphQLClient: GraphQLClient
4747
) {
48-
suspend fun interfaceWithInlineFragmentsTestQuery():
48+
suspend fun execute():
4949
GraphQLResult<InterfaceWithInlineFragmentsTestQuery.InterfaceWithInlineFragmentsTestQueryResult>
5050
= graphQLClient.execute(INTERFACE_WITH_INLINE_FRAGMENTS_TEST_QUERY,
5151
"InterfaceWithInlineFragmentsTestQuery", null)
@@ -159,7 +159,7 @@ class GenerateGraphQLInterfaceTypeSpecIT {
159159
class InterfaceWithNamedFragmentsTestQuery(
160160
private val graphQLClient: GraphQLClient
161161
) {
162-
suspend fun interfaceWithNamedFragmentsTestQuery():
162+
suspend fun execute():
163163
GraphQLResult<InterfaceWithNamedFragmentsTestQuery.InterfaceWithNamedFragmentsTestQueryResult>
164164
= graphQLClient.execute(INTERFACE_WITH_NAMED_FRAGMENTS_TEST_QUERY,
165165
"InterfaceWithNamedFragmentsTestQuery", null)

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLObjectTypeSpecIT.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class GenerateGraphQLObjectTypeSpecIT {
4242
class ComplexObjectTestQuery(
4343
private val graphQLClient: GraphQLClient
4444
) {
45-
suspend fun complexObjectTestQuery():
46-
GraphQLResult<ComplexObjectTestQuery.ComplexObjectTestQueryResult> =
45+
suspend fun execute(): GraphQLResult<ComplexObjectTestQuery.ComplexObjectTestQueryResult> =
4746
graphQLClient.execute(COMPLEX_OBJECT_TEST_QUERY, "ComplexObjectTestQuery", null)
4847
4948
/**
@@ -130,7 +129,7 @@ class GenerateGraphQLObjectTypeSpecIT {
130129
class ComplexObjectQueryWithNamedFragment(
131130
private val graphQLClient: GraphQLClient
132131
) {
133-
suspend fun complexObjectQueryWithNamedFragment():
132+
suspend fun execute():
134133
GraphQLResult<ComplexObjectQueryWithNamedFragment.ComplexObjectQueryWithNamedFragmentResult> =
135134
graphQLClient.execute(COMPLEX_OBJECT_QUERY_WITH_NAMED_FRAGMENT,
136135
"ComplexObjectQueryWithNamedFragment", null)
@@ -250,7 +249,7 @@ class GenerateGraphQLObjectTypeSpecIT {
250249
class JUnitTestQuery(
251250
private val graphQLClient: GraphQLClient
252251
) {
253-
suspend fun jUnitTestQuery(): GraphQLResult<JUnitTestQuery.JUnitTestQueryResult> =
252+
suspend fun execute(): GraphQLResult<JUnitTestQuery.JUnitTestQueryResult> =
254253
graphQLClient.execute(J_UNIT_TEST_QUERY, "JUnitTestQuery", null)
255254
256255
/**
@@ -311,8 +310,8 @@ class GenerateGraphQLObjectTypeSpecIT {
311310
class DeprecatedFieldQuery(
312311
private val graphQLClient: GraphQLClient
313312
) {
314-
suspend fun deprecatedFieldQuery(): GraphQLResult<DeprecatedFieldQuery.DeprecatedFieldQueryResult>
315-
= graphQLClient.execute(DEPRECATED_FIELD_QUERY, "DeprecatedFieldQuery", null)
313+
suspend fun execute(): GraphQLResult<DeprecatedFieldQuery.DeprecatedFieldQueryResult> =
314+
graphQLClient.execute(DEPRECATED_FIELD_QUERY, "DeprecatedFieldQuery", null)
316315
317316
data class DeprecatedFieldQueryResult(
318317
/**
@@ -355,7 +354,7 @@ class GenerateGraphQLObjectTypeSpecIT {
355354
class NestedQuery(
356355
private val graphQLClient: GraphQLClient
357356
) {
358-
suspend fun nestedQuery(): GraphQLResult<NestedQuery.NestedQueryResult> =
357+
suspend fun execute(): GraphQLResult<NestedQuery.NestedQueryResult> =
359358
graphQLClient.execute(NESTED_QUERY, "NestedQuery", null)
360359
361360
/**

plugins/graphql-kotlin-plugin-core/src/test/kotlin/com/expediagroup/graphql/plugin/generator/types/GenerateGraphQLUnionTypeSpecIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GenerateGraphQLUnionTypeSpecIT {
4545
class UnionQueryWithInlineFragments(
4646
private val graphQLClient: GraphQLClient
4747
) {
48-
suspend fun unionQueryWithInlineFragments():
48+
suspend fun execute():
4949
GraphQLResult<UnionQueryWithInlineFragments.UnionQueryWithInlineFragmentsResult> =
5050
graphQLClient.execute(UNION_QUERY_WITH_INLINE_FRAGMENTS, "UnionQueryWithInlineFragments",
5151
null)
@@ -143,7 +143,7 @@ class GenerateGraphQLUnionTypeSpecIT {
143143
class UnionQueryWithNamedFragments(
144144
private val graphQLClient: GraphQLClient
145145
) {
146-
suspend fun unionQueryWithNamedFragments():
146+
suspend fun execute():
147147
GraphQLResult<UnionQueryWithNamedFragments.UnionQueryWithNamedFragmentsResult> =
148148
graphQLClient.execute(UNION_QUERY_WITH_NAMED_FRAGMENTS, "UnionQueryWithNamedFragments", null)
149149

0 commit comments

Comments
 (0)