You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[plugin] support generating graphql client test sources (#718)
* [plugin] support generating graphql client test sources
Generate GraphQL client Gradle task and Maven Mojo now accept optional `generateTestSources` boolean parameter to indicate generation of test sources.
Resolves: #706
* fix example maven client
* fix test
* separate generateTestClient task/mojo
* update docs
* revert some docs to old format
Copy file name to clipboardExpand all lines: docs/plugins/gradle-plugin.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,8 @@ graphql {
41
41
allowDeprecatedFields =false
42
42
// Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
// Boolean flag indicating whether generated GraphQL client should be added to main or test sources.
45
+
generateTestSources =false
44
46
}
45
47
```
46
48
@@ -66,7 +68,7 @@ and could be used as an alternative to `graphqlIntrospectSchema` to generate inp
66
68
67
69
Task that generates GraphQL Kotlin client and corresponding data classes based on the provided GraphQL queries that are
68
70
evaluated against target Graphql schema. Individual clients with their specific data models are generated for each query
69
-
file and are placed under specified `packageName`.
71
+
file and are placed under specified `packageName`. Generated code is automatically added to the project main source set.
70
72
71
73
**Properties**
72
74
@@ -80,6 +82,24 @@ file and are placed under specified `packageName`.
80
82
|`schemaFile`| File |`schemaFileName` or `schemaFile` has to be provided | GraphQL schema file that will be used to generate client code. |
81
83
|`schemaFileName`| String |`schemaFileName` or `schemaFile` has to be provided | Path to GraphQL schema file that will be used to generate client code.<br/>**Command line property is**: `schemaFileName`. |
82
84
85
+
### graphqlGenerateTestClient
86
+
87
+
Task that generates GraphQL Kotlin test client and corresponding data classes based on the provided GraphQL queries that are
88
+
evaluated against target Graphql schema. Individual test clients with their specific data models are generated for each query
89
+
file and are placed under specified `packageName`. Generated code is automatically added to the project test source set.
90
+
91
+
**Properties**
92
+
93
+
| Property | Type | Required | Description |
94
+
| -------- | ---- | -------- | ----------- |
95
+
|`allowDeprecatedFields`| Boolean || Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:**`false`.<br/>**Command line property is**: `allowDeprecatedFields`. |
96
+
|`converters`| Map<String, ScalarConverter> || Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
97
+
|`packageName`| String | yes | Target package name for generated code.<br/>**Command line property is**: `packageName`. |
98
+
|`queryFiles`| FileCollection || List of query files to be processed. Instead of a list of files to be processed you can specify `queryFileDirectory` directory instead. If this property is specified it will take precedence over the corresponding directory property. |
99
+
|`queryFileDirectory`| String || Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:**`src/test/resources`.<br/>**Command line property is**: `queryFileDirectory`. |
100
+
|`schemaFile`| File |`schemaFileName` or `schemaFile` has to be provided | GraphQL schema file that will be used to generate client code. |
101
+
|`schemaFileName`| String |`schemaFileName` or `schemaFile` has to be provided | Path to GraphQL schema file that will be used to generate client code.<br/>**Command line property is**: `schemaFileName`. |
102
+
83
103
### graphqlIntrospectSchema
84
104
85
105
Task that executes GraphQL introspection query against specified `endpoint` and saves the underlying schema file as
Copy file name to clipboardExpand all lines: docs/plugins/maven-plugin.md
+46-4Lines changed: 46 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,12 +45,51 @@ Generate GraphQL client code based on the provided GraphQL schema and target que
45
45
| -------- | ---- | -------- | ----------- |
46
46
|`allowDeprecatedFields`| Boolean || Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:**`false`.<br/>**User property is**: `graphql.allowDeprecatedFields`. |
47
47
|`converters`| Map<String, ScalarConverter> || Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
48
-
|`outputDirectory`| File || Target directory where to store generated files.<br/>**Default value is**: `${project.build.directory}/generated/sources/graphql`|
48
+
|`outputDirectory`| File || Target directory where to store generated files.<br/>**Default value is**: `${project.build.directory}/generated-sources/graphql`|
49
49
|`packageName`| String | yes | Target package name for generated code.<br/>**User property is**: `graphql.packageName`. |
50
50
|`queryFileDirectory`| File || Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:**`src/main/resources`. |
51
51
|`queryFiles`| List<File> || List of query files to be processed. Instead of a list of files to be processed you can also specify `queryFileDirectory` directory containing all the files. If this property is specified it will take precedence over the corresponding directory property. |
52
52
|`schemaFile`| String | yes | GraphQL schema file that will be used to generate client code.<br/>**User property is**: `graphql.schemaFile`. |
53
53
54
+
**Parameter Details**
55
+
56
+
**converters* - Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
57
+
58
+
```xml
59
+
<converters>
60
+
<!-- custom scalar type -->
61
+
<UUID>
62
+
<!-- fully qualified Java class name of a custom scalar type -->
63
+
<type>java.util.UUID</type>
64
+
<!-- fully qualified Java class name of a custom com.expediagroup.graphql.client.converter.ScalarConverter
65
+
used to convert to/from raw JSON and scalar type -->
* Generated classes are automatically added to the list of test compiled sources.
80
+
81
+
**Parameters**
82
+
83
+
| Property | Type | Required | Description |
84
+
| -------- | ---- | -------- | ----------- |
85
+
| `allowDeprecatedFields` | Boolean | | Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:** `false`.<br/>**User property is**: `graphql.allowDeprecatedFields`. |
86
+
| `converters` | Map<String, ScalarConverter> | | Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
87
+
| `outputDirectory` | File | | Target directory where to store generated files.<br/>**Default value is**: `${project.build.directory}/generated-test-sources/graphql` |
88
+
| `packageName` | String | yes | Target package name for generated code.<br/>**User property is**: `graphql.packageName`. |
89
+
| `queryFileDirectory` | File | | Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:** `src/test/resources`. |
90
+
| `queryFiles` | List<File> | | List of query files to be processed. Instead of a list of files to be processed you can also specify `queryFileDirectory` directory containing all the files. If this property is specified it will take precedence over the corresponding directory property. |
91
+
| `schemaFile` | String | yes | GraphQL schema file that will be used to generate client code.<br/>**User property is**: `graphql.schemaFile`. |
92
+
54
93
**Parameter Details**
55
94
56
95
* *converters* - Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
@@ -185,6 +224,9 @@ Mojo can also be configured in your Maven build file and it provides additional
185
224
This will process all GraphQL queries located under `src/main/resources` and generate corresponding GraphQL Kotlin clients.
186
225
Generated classes will be automatically added to the project compile sources.
187
226
227
+
>NOTE: You might need to explicitly add generated clients to your project sources for your IDE to recognize them. See
228
+
>[build-helper-maven-plugin](https://www.mojohaus.org/build-helper-maven-plugin/) for details.
229
+
188
230
### Generating Client with Custom Scalars
189
231
190
232
By default, all custom GraphQL scalars will be serialized as Strings. You can override this default behavior by specifying
@@ -277,6 +319,6 @@ This generated schema is subsequently used to generate GraphQL client code based
277
319
</plugin>
278
320
```
279
321
280
-
NOTE: Both `introspectSchema` and `generateClient` goals are bound to the same `generate-sources` Maven lifecycle phase.
281
-
As opposed to Gradle, Maven does not support explicit dependencies between different goals and they will be executed in
282
-
the order they are defined in your `pom.xml` build file.
322
+
>NOTE: Both `introspectSchema` and `generateClient` goals are bound to the same `generate-sources` Maven lifecycle phase.
323
+
>As opposed to Gradle, Maven does not support explicit ordering of goals. Maven Mojos will be executed in the order they
Copy file name to clipboardExpand all lines: plugins/graphql-kotlin-gradle-plugin/README.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ and could be used as an alternative to `graphqlIntrospectSchema` to generate inp
51
51
52
52
Task that generates GraphQL Kotlin client and corresponding data classes based on the provided GraphQL queries that are
53
53
evaluated against target Graphql schema. Individual clients with their specific data models are generated for each query
54
-
file and are placed under specified `packageName`.
54
+
file and are placed under specified `packageName`. Generated code is automatically added to the project main source set.
55
55
56
56
**Properties**
57
57
@@ -65,6 +65,24 @@ file and are placed under specified `packageName`.
65
65
|`schemaFile`| File |`schemaFileName` or `schemaFile` has to be provided | GraphQL schema file that will be used to generate client code. |
66
66
|`schemaFileName`| String |`schemaFileName` or `schemaFile` has to be provided | Path to GraphQL schema file that will be used to generate client code.<br/>**Command line property is**: `schemaFileName`. |
67
67
68
+
### graphqlGenerateTestClient
69
+
70
+
Task that generates GraphQL Kotlin test client and corresponding data classes based on the provided GraphQL queries that are
71
+
evaluated against target Graphql schema. Individual test clients with their specific data models are generated for each query
72
+
file and are placed under specified `packageName`. Generated code is automatically added to the project test source set.
73
+
74
+
**Properties**
75
+
76
+
| Property | Type | Required | Description |
77
+
| -------- | ---- | -------- | ----------- |
78
+
|`allowDeprecatedFields`| Boolean || Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:**`false`.<br/>**Command line property is**: `allowDeprecatedFields`. |
79
+
|`converters`| Map<String, ScalarConverter> || Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
80
+
|`packageName`| String | yes | Target package name for generated code.<br/>**Command line property is**: `packageName`. |
81
+
|`queryFiles`| FileCollection || List of query files to be processed. Instead of a list of files to be processed you can specify `queryFileDirectory` directory instead. If this property is specified it will take precedence over the corresponding directory property. |
82
+
|`queryFileDirectory`| String || Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:**`src/test/resources`.<br/>**Command line property is**: `queryFileDirectory`. |
83
+
|`schemaFile`| File |`schemaFileName` or `schemaFile` has to be provided | GraphQL schema file that will be used to generate client code. |
84
+
|`schemaFileName`| String |`schemaFileName` or `schemaFile` has to be provided | Path to GraphQL schema file that will be used to generate client code.<br/>**Command line property is**: `schemaFileName`. |
85
+
68
86
### graphqlIntrospectSchema
69
87
70
88
Task that executes GraphQL introspection query against specified `endpoint` and saves the underlying schema file as
Copy file name to clipboardExpand all lines: plugins/graphql-kotlin-gradle-plugin/src/main/kotlin/com/expediagroup/graphql/plugin/gradle/GraphQLGradlePlugin.kt
Copy file name to clipboardExpand all lines: plugins/graphql-kotlin-gradle-plugin/src/main/kotlin/com/expediagroup/graphql/plugin/gradle/tasks/GraphQLGenerateClientTask.kt
0 commit comments