Skip to content

Commit 82bea4e

Browse files
committed
update tests
1 parent 5065324 commit 82bea4e

File tree

1 file changed

+22
-9
lines changed
  • tests/compiler-plugins/add-field/src/main/kotlin/hooks

1 file changed

+22
-9
lines changed

tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hooks
22

3+
import com.apollographql.apollo.ast.GQLDocument
34
import com.apollographql.apollo.ast.GQLField
45
import com.apollographql.apollo.ast.GQLFragmentDefinition
56
import com.apollographql.apollo.ast.GQLFragmentSpread
@@ -25,15 +26,27 @@ class TestPluginProvider: ApolloCompilerPluginProvider {
2526
class TestPlugin : ApolloCompilerPlugin {
2627
override fun documentTransform(): DocumentTransform {
2728
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+
}
3750
)
3851
}
3952
}

0 commit comments

Comments
 (0)