Skip to content

Commit 635a93b

Browse files
authored
Add @map and @mapTo (#6404)
* Add @Map and @mapto * unbreak Gradle tests
1 parent e0ad0a4 commit 635a93b

File tree

134 files changed

+1697
-931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1697
-931
lines changed

.idea/runConfigurations/CodegenTest.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/ValidationTest.xml

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-logic/src/main/kotlin/api.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fun Project.apolloLibrary(
4848
configurePublishing()
4949
}
5050

51-
// Within the 'tests' project (a composite build), dependencies are automatically substituted to use the project's one.
52-
// But we don't want this, for example apollo-tooling depends on a published version of apollo-api.
53-
// So disable this behavior (see https://docs.gradle.org/current/userguide/composite_builds.html#deactivate_included_build_substitutions).
5451
configurations.configureEach {
55-
if (name != "apolloPublished") {
56-
return@configureEach
52+
if (name == "apolloPublished" || name.matches(Regex("apollo.*Compiler"))) {
53+
// Within the 'tests' project (a composite build), dependencies are automatically substituted to use the project's one.
54+
// apollo-tooling depends on a published version of apollo-api which should not be substituted for both the runtime
55+
// and compiler classpaths.
56+
// See (see https://docs.gradle.org/current/userguide/composite_builds.html#deactivate_included_build_substitutions).
57+
this.resolutionStrategy.useGlobalDependencySubstitutionRules.set(false)
5758
}
58-
resolutionStrategy.useGlobalDependencySubstitutionRules.set(false)
5959
}
6060

6161
if (extensions.findByName("kotlin") is KotlinMultiplatformExtension) {

design-docs/Scalar adapter configuration.md

Lines changed: 0 additions & 210 deletions
This file was deleted.

libraries/apollo-ast/api/apollo-ast.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ final class com.apollographql.apollo.ast/GQLInputValueDefinition : com.apollogra
517517
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String?, kotlin/String, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective>, com.apollographql.apollo.ast/GQLType, com.apollographql.apollo.ast/GQLValue?) // com.apollographql.apollo.ast/GQLInputValueDefinition.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>;com.apollographql.apollo.ast.GQLType;com.apollographql.apollo.ast.GQLValue?){}[0]
518518

519519
final val children // com.apollographql.apollo.ast/GQLInputValueDefinition.children|{}children[0]
520-
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> // com.apollographql.apollo.ast/GQLInputValueDefinition.children.<get-children>|<get-children>(){}[0]
520+
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLNode> // com.apollographql.apollo.ast/GQLInputValueDefinition.children.<get-children>|<get-children>(){}[0]
521521
final val defaultValue // com.apollographql.apollo.ast/GQLInputValueDefinition.defaultValue|{}defaultValue[0]
522522
final fun <get-defaultValue>(): com.apollographql.apollo.ast/GQLValue? // com.apollographql.apollo.ast/GQLInputValueDefinition.defaultValue.<get-defaultValue>|<get-defaultValue>(){}[0]
523523
final val description // com.apollographql.apollo.ast/GQLInputValueDefinition.description|{}description[0]

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/Schema.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ class Schema internal constructor(
229229
@ApolloExperimental
230230
const val FIELD_POLICY_PAGINATION_ARGS = "paginationArgs"
231231

232+
@ApolloExperimental
233+
const val MAP = "map"
234+
235+
@ApolloExperimental
236+
const val MAP_TO = "mapTo"
237+
232238
/**
233239
* Parses the given [map] and creates a new [Schema].
234240
* The [map] must come from a previous call to [toMap] to make sure the schema is valid

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/gql.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ class GQLInputValueDefinition(
11611161
val defaultValue: GQLValue?,
11621162
) : GQLNode, GQLDescribed, GQLNamed, GQLHasDirectives {
11631163

1164-
override val children = directives
1164+
override val children: List<GQLNode> = directives + type + listOfNotNull(defaultValue)
11651165

11661166
/**
11671167
* @param inline whether the input value definition is used inline (for an example a field argument)
@@ -1217,7 +1217,9 @@ class GQLInputValueDefinition(
12171217

12181218
override fun copyWithNewChildrenInternal(container: NodeContainer): GQLNode {
12191219
return copy(
1220-
directives = container.take()
1220+
directives = container.take(),
1221+
type = container.takeSingle()!!,
1222+
defaultValue = container.takeSingle()
12211223
)
12221224
}
12231225
}

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/gqldirective.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ fun GQLFieldDefinition.findSemanticNonNulls(schema: Schema): List<Int> {
199199
}
200200
return semanticNonNull.getArgumentValueOrDefault("levels", schema)!!.toListOfInt()
201201
}
202+
203+

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/gqldocument.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import com.apollographql.apollo.annotations.ApolloExperimental
55
import com.apollographql.apollo.annotations.ApolloInternal
66
import com.apollographql.apollo.ast.internal.ExtensionsMerger
77
import com.apollographql.apollo.ast.internal.builtinsDefinitionsStr
8+
import com.apollographql.apollo.ast.internal.compilerOptions_0_0
89
import com.apollographql.apollo.ast.internal.kotlinLabsDefinitions_0_3
910
import com.apollographql.apollo.ast.internal.kotlinLabsDefinitions_0_4
11+
import com.apollographql.apollo.ast.internal.kotlinLabsDefinitions_0_5
1012
import com.apollographql.apollo.ast.internal.linkDefinitionsStr
1113
import com.apollographql.apollo.ast.internal.nullabilityDefinitionsStr
1214
import okio.Buffer
@@ -127,6 +129,8 @@ fun kotlinLabsDefinitions(version: String): List<GQLDefinition> {
127129
"v0.2", "v0.3" -> kotlinLabsDefinitions_0_3
128130
// v0.4 doesn't have `@nonnull`
129131
"v0.4" -> kotlinLabsDefinitions_0_4
132+
// v0.5 adds `@map` and `@mapTo`
133+
"v0.5" -> kotlinLabsDefinitions_0_5
130134
else -> error("kotlin_labs/$version definitions are not supported, please use $AUTO_IMPORTED_KOTLIN_LABS_VERSION")
131135
})
132136
}
@@ -143,7 +147,9 @@ fun builtinForeignSchemas(): List<ForeignSchema> {
143147
ForeignSchema("kotlin_labs", "v0.2", kotlinLabsDefinitions("v0.2"), listOf("optional", "nonnull")),
144148
autoLinkedKotlinLabsForeignSchema,
145149
ForeignSchema("kotlin_labs", "v0.4", kotlinLabsDefinitions("v0.4"), listOf("optional")),
150+
ForeignSchema("kotlin_labs", "v0.5", kotlinLabsDefinitions("v0.5"), listOf("optional")),
146151
ForeignSchema("nullability", "v0.4", nullabilityDefinitions("v0.4"), listOf("catch")),
152+
ForeignSchema("kotlin_compiler_options", "v0.0", definitionsFromString(compilerOptions_0_0), emptyList())
147153
)
148154
}
149155

@@ -198,7 +204,10 @@ internal fun combineDefinitions(
198204
check(builtInTypeDefinition is GQLNamed) {
199205
"only extra named definitions are supported"
200206
}
201-
val existingDefinition = mergedDefinitions.firstOrNull { (it as? GQLNamed)?.name == builtInTypeDefinition.name }
207+
val existingDefinition = mergedDefinitions.firstOrNull {
208+
builtInTypeDefinition::class == it::class
209+
&& (it as? GQLNamed)?.name == builtInTypeDefinition.name
210+
}
202211
if (existingDefinition == null) {
203212
mergedDefinitions.add(builtInTypeDefinition)
204213
}
@@ -208,7 +217,6 @@ internal fun combineDefinitions(
208217
}
209218

210219

211-
212220
/**
213221
* Outputs a schema document to SDL. For executable documents, use toUtf8()
214222
*

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/ExtensionsMerger.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private inline fun <reified T, E> ExtensionsMerger.mergeTypedDefinition(
160160
) where T : GQLDefinition, E : GQLTypeSystemExtension {
161161
val index = newDefinitions.indexOfFirst { it is T }
162162
if (index == -1) {
163-
issues.add(OtherValidationIssue("Cannot find $extra definition to apply extension", extension.sourceLocation))
163+
issues.add(OtherValidationIssue("Cannot find $extra definition to apply the following extension:\n${extension.toUtf8()}", extension.sourceLocation))
164164
} else {
165165
newDefinitions.set(index, merge(newDefinitions[index] as T))
166166
}
@@ -188,7 +188,7 @@ private inline fun <reified T, E> ExtensionsMerger.mergeNamedDefinition(
188188

189189
when (indexedValues.size) {
190190
0 -> {
191-
issues.add(OtherValidationIssue("Cannot find $extra type `${extension.name}` to apply extension", extension.sourceLocation))
191+
issues.add(OtherValidationIssue("Cannot find $extra type `${extension.name}` to apply the following extension:\n${extension.toUtf8()}", extension.sourceLocation))
192192
}
193193

194194
1 -> {

0 commit comments

Comments
 (0)