File tree Expand file tree Collapse file tree 1 file changed +22
-9
lines changed
tests/compiler-plugins/add-field/src/main/kotlin/hooks Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change 1
1
package hooks
2
2
3
+ import com.apollographql.apollo.ast.GQLDocument
3
4
import com.apollographql.apollo.ast.GQLField
4
5
import com.apollographql.apollo.ast.GQLFragmentDefinition
5
6
import com.apollographql.apollo.ast.GQLFragmentSpread
@@ -25,15 +26,27 @@ class TestPluginProvider: ApolloCompilerPluginProvider {
25
26
class TestPlugin : ApolloCompilerPlugin {
26
27
override fun documentTransform (): DocumentTransform {
27
28
return object : DocumentTransform {
28
- override fun transform (schema : Schema , operation : GQLOperationDefinition ): GQLOperationDefinition {
29
- return operation.copy(
30
- selections = operation.selections.alwaysGreet(schema, operation.rootTypeDefinition(schema)!! .name)
31
- )
32
- }
33
-
34
- override fun transform (schema : Schema , fragment : GQLFragmentDefinition ): GQLFragmentDefinition {
35
- return fragment.copy(
36
- selections = fragment.selections.alwaysGreet(schema, fragment.typeCondition.name)
29
+ override fun transform (
30
+ schema : Schema ,
31
+ document : GQLDocument ,
32
+ extraFragmentDefinitions : List <GQLFragmentDefinition >,
33
+ ): GQLDocument {
34
+ return document.copy(
35
+ definitions = document.definitions.map {
36
+ when (it) {
37
+ is GQLOperationDefinition -> {
38
+ it.copy(
39
+ selections = it.selections.alwaysGreet(schema, it.rootTypeDefinition(schema)!! .name)
40
+ )
41
+ }
42
+ is GQLFragmentDefinition -> {
43
+ it.copy(
44
+ selections = it.selections.alwaysGreet(schema, it.typeCondition.name)
45
+ )
46
+ }
47
+ else -> it
48
+ }
49
+ }
37
50
)
38
51
}
39
52
}
You can’t perform that action at this time.
0 commit comments