-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add DocumentTransform API * Fix ConditionalFragments test * Add link to the documentation * add missing parameter
- Loading branch information
1 parent
6ee32df
commit c016f84
Showing
16 changed files
with
206 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") | ||
} | ||
|
||
apolloTest() | ||
|
||
dependencies { | ||
implementation(libs.apollo.compiler) | ||
implementation(libs.apollo.ast) | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/compiler-plugins/add-field/src/main/kotlin/hooks/TestPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package hooks | ||
|
||
import com.apollographql.apollo3.ast.GQLField | ||
import com.apollographql.apollo3.ast.GQLFragmentDefinition | ||
import com.apollographql.apollo3.ast.GQLFragmentSpread | ||
import com.apollographql.apollo3.ast.GQLInlineFragment | ||
import com.apollographql.apollo3.ast.GQLOperationDefinition | ||
import com.apollographql.apollo3.ast.GQLSelection | ||
import com.apollographql.apollo3.ast.Schema | ||
import com.apollographql.apollo3.ast.definitionFromScope | ||
import com.apollographql.apollo3.ast.rawType | ||
import com.apollographql.apollo3.ast.responseName | ||
import com.apollographql.apollo3.ast.rootTypeDefinition | ||
import com.apollographql.apollo3.compiler.DocumentTransform | ||
import com.apollographql.apollo3.compiler.Plugin | ||
|
||
class TestPlugin : Plugin { | ||
override fun documentTransform(): DocumentTransform { | ||
return object : DocumentTransform { | ||
override fun transform(schema: Schema, operation: GQLOperationDefinition): GQLOperationDefinition { | ||
return operation.copy( | ||
selections = operation.selections.alwaysGreet(schema, operation.rootTypeDefinition(schema)!!.name) | ||
) | ||
} | ||
|
||
override fun transform(schema: Schema, fragment: GQLFragmentDefinition): GQLFragmentDefinition { | ||
return fragment.copy( | ||
selections = fragment.selections.alwaysGreet(schema, fragment.typeCondition.name) | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun List<GQLSelection>.alwaysGreet(schema: Schema, parentType: String): List<GQLSelection> { | ||
val selections = this.map { | ||
when (it) { | ||
is GQLField -> it.copy( | ||
selections = it.selections.alwaysGreet(schema, it.definitionFromScope(schema, parentType)!!.type.rawType().name) | ||
) | ||
is GQLFragmentSpread -> it | ||
is GQLInlineFragment -> it.copy( | ||
selections = it.selections.alwaysGreet(schema, it.typeCondition?.name ?: parentType) | ||
) | ||
} | ||
} | ||
|
||
return if (parentType == "Friend" && selections.none { it is GQLField && it.responseName() == "greet" }) { | ||
selections + GQLField(null, null, "greet", emptyList(), emptyList(), emptyList()) | ||
} else { | ||
selections | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../add-field/src/main/resources/META-INF/services/com.apollographql.apollo3.compiler.Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hooks.TestPlugin |
Oops, something went wrong.