Skip to content

Commit df1bf18

Browse files
authored
Add support for onError (#6860)
1 parent fdaf623 commit df1bf18

File tree

20 files changed

+1754
-362
lines changed

20 files changed

+1754
-362
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public final class com/apollographql/apollo/ast/GQLCapability : com/apollographq
196196
public fun copyWithNewChildrenInternal (Lcom/apollographql/apollo/ast/NodeContainer;)Lcom/apollographql/apollo/ast/GQLNode;
197197
public fun getChildren ()Ljava/util/List;
198198
public final fun getDescription ()Ljava/lang/String;
199-
public final fun getQualifiedName ()Ljava/lang/String;
199+
public final fun getName ()Ljava/lang/String;
200200
public fun getSourceLocation ()Lcom/apollographql/apollo/ast/SourceLocation;
201201
public final fun getValue ()Ljava/lang/String;
202202
public fun writeInternal (Lcom/apollographql/apollo/ast/SDLWriter;)V

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ final class com.apollographql.apollo.ast/GQLCapability : com.apollographql.apoll
321321
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLNode> // com.apollographql.apollo.ast/GQLCapability.children.<get-children>|<get-children>(){}[0]
322322
final val description // com.apollographql.apollo.ast/GQLCapability.description|{}description[0]
323323
final fun <get-description>(): kotlin/String? // com.apollographql.apollo.ast/GQLCapability.description.<get-description>|<get-description>(){}[0]
324-
final val qualifiedName // com.apollographql.apollo.ast/GQLCapability.qualifiedName|{}qualifiedName[0]
325-
final fun <get-qualifiedName>(): kotlin/String // com.apollographql.apollo.ast/GQLCapability.qualifiedName.<get-qualifiedName>|<get-qualifiedName>(){}[0]
324+
final val name // com.apollographql.apollo.ast/GQLCapability.name|{}name[0]
325+
final fun <get-name>(): kotlin/String // com.apollographql.apollo.ast/GQLCapability.name.<get-name>|<get-name>(){}[0]
326326
final val sourceLocation // com.apollographql.apollo.ast/GQLCapability.sourceLocation|{}sourceLocation[0]
327327
final fun <get-sourceLocation>(): com.apollographql.apollo.ast/SourceLocation? // com.apollographql.apollo.ast/GQLCapability.sourceLocation.<get-sourceLocation>|<get-sourceLocation>(){}[0]
328328
final val value // com.apollographql.apollo.ast/GQLCapability.value|{}value[0]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ class GQLServiceExtension(
438438
class GQLCapability(
439439
override val sourceLocation: SourceLocation? = null,
440440
val description: String?,
441-
val qualifiedName: String,
441+
val name: String,
442442
val value: String?,
443443
) : GQLNode {
444444
override val children: List<GQLNode>
@@ -448,7 +448,7 @@ class GQLCapability(
448448
with(writer) {
449449
writeDescription(description)
450450
write("capability ")
451-
write(qualifiedName)
451+
write(name)
452452
if (value != null) {
453453
write("(\"$value\")")
454454
}
@@ -459,13 +459,13 @@ class GQLCapability(
459459
fun copy(
460460
sourceLocation: SourceLocation? = this.sourceLocation,
461461
description: String? = this.description,
462-
qualifiedName: String = this.qualifiedName,
462+
qualifiedName: String = this.name,
463463
value: String? = this.value,
464464
): GQLCapability {
465465
return GQLCapability(
466466
sourceLocation = sourceLocation,
467467
description = description,
468-
qualifiedName = qualifiedName,
468+
name = qualifiedName,
469469
value = value
470470
)
471471
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private fun ExtensionsMerger.mergeService(
283283
): GQLServiceDefinition = with(serviceDefinition) {
284284
return copy(
285285
directives = mergeDirectives(directives, extension.directives),
286-
capabilities = mergeUniquesOrThrow(capabilities, extension.capabilities) { it.qualifiedName }
286+
capabilities = mergeUniquesOrThrow(capabilities, extension.capabilities) { it.name }
287287
)
288288
}
289289

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ internal class Parser(
368368
return GQLCapability(
369369
sourceLocation = sourceLocation(start),
370370
description = description,
371-
qualifiedName = qualifiedName,
371+
name = qualifiedName,
372372
value = value
373373
)
374374
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ internal fun validateSchema(definitions: List<GQLDefinition>, options: SchemaVal
8989
val typeSystemExtensions = mutableListOf<GQLTypeSystemExtension>()
9090
var schemaDefinition: GQLSchemaDefinition? = null
9191
val reportedDefinitions = mutableSetOf<GQLDefinition>()
92+
var serviceDefinition: GQLServiceDefinition? = null
9293

9394
/*
9495
* Deduplicate the user input
@@ -139,6 +140,7 @@ internal fun validateSchema(definitions: List<GQLDefinition>, options: SchemaVal
139140
}
140141

141142
is GQLServiceDefinition -> {
143+
serviceDefinition = definition
142144
// TODO: any validation to do here?
143145
// See https://github.com/graphql/graphql-spec/pull/1208/changes#r2732688632
144146
}
@@ -303,7 +305,7 @@ internal fun validateSchema(definitions: List<GQLDefinition>, options: SchemaVal
303305
*
304306
* Moving forward, extensions merging should probably be done first thing as a separate step, before any validation and/or linking of foreign schemas.
305307
*/
306-
val dedupedDefinitions = listOfNotNull(schemaDefinition) + directiveDefinitions.values + typeDefinitions.values
308+
val dedupedDefinitions = listOfNotNull(schemaDefinition) + directiveDefinitions.values + typeDefinitions.values + listOfNotNull(serviceDefinition)
307309
val mergedDefinitions = ExtensionsMerger(dedupedDefinitions + typeSystemExtensions, options.mergeOptions).merge().getOrThrow()
308310

309311
val mergedScope = DefaultValidationScope(

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.apollographql.apollo.ast.introspection
77

88
import com.apollographql.apollo.annotations.ApolloExperimental
9-
import com.apollographql.apollo.annotations.ApolloInternal
109
import com.apollographql.apollo.ast.*
1110
import kotlinx.serialization.KSerializer
1211
import kotlinx.serialization.Serializable
@@ -479,7 +478,7 @@ private class GQLDocumentBuilder(private val introspectionSchema: IntrospectionS
479478
private fun RCapability.toGQLCapability(): GQLCapability {
480479
return GQLCapability(
481480
description = description.unwrapDescription(qualifiedName),
482-
qualifiedName = qualifiedName,
481+
name = qualifiedName,
483482
value = value.getOrThrow()
484483
)
485484
}

libraries/apollo-ast/src/jvmTest/kotlin/com/apollographql/apollo/graphql/ast/test/fixtures.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ internal fun GQLResult<GQLDocument>.serialize(): String {
2828
}
2929
}
3030

31-
fun shouldUpdateTestFixtures(): Boolean {
32-
if (System.getenv("updateTestFixtures") != null) {
33-
return true
34-
}
35-
36-
return false
37-
}
31+
fun shouldUpdateTestFixtures() = System.getenv("updateTestFixtures") != null
3832

3933
internal fun testFilterMatches(value: String): Boolean {
4034
val testFilter = System.getenv("testFilter") ?: return true

libraries/apollo-execution/api/apollo-execution.api

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public final class com/apollographql/apollo/execution/ErrorPersistedDocument : c
2020
}
2121

2222
public final class com/apollographql/apollo/execution/ExecutableSchema {
23-
public fun <init> (Lcom/apollographql/apollo/ast/Schema;Ljava/util/Map;Lcom/apollographql/apollo/execution/RootResolver;Lcom/apollographql/apollo/execution/RootResolver;Lcom/apollographql/apollo/execution/RootResolver;Lcom/apollographql/apollo/execution/Resolver;Lcom/apollographql/apollo/execution/TypeResolver;Ljava/util/List;Lcom/apollographql/apollo/execution/PersistedDocumentCache;)V
2423
public final fun execute (Lcom/apollographql/apollo/execution/GraphQLRequest;Lcom/apollographql/apollo/api/ExecutionContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
2524
public static synthetic fun execute$default (Lcom/apollographql/apollo/execution/ExecutableSchema;Lcom/apollographql/apollo/execution/GraphQLRequest;Lcom/apollographql/apollo/api/ExecutionContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
2625
public final fun subscribe (Lcom/apollographql/apollo/execution/GraphQLRequest;Lcom/apollographql/apollo/api/ExecutionContext;)Lkotlinx/coroutines/flow/Flow;
@@ -33,6 +32,7 @@ public final class com/apollographql/apollo/execution/ExecutableSchema$Builder {
3332
public final fun addInstrumentation (Lcom/apollographql/apollo/execution/Instrumentation;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
3433
public final fun build ()Lcom/apollographql/apollo/execution/ExecutableSchema;
3534
public final fun mutationRoot (Lcom/apollographql/apollo/execution/RootResolver;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
35+
public final fun onError (Lcom/apollographql/apollo/execution/OnError;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
3636
public final fun persistedDocumentCache (Lcom/apollographql/apollo/execution/PersistedDocumentCache;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
3737
public final fun queryRoot (Lcom/apollographql/apollo/execution/RootResolver;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
3838
public final fun resolver (Lcom/apollographql/apollo/execution/Resolver;)Lcom/apollographql/apollo/execution/ExecutableSchema$Builder;
@@ -59,6 +59,7 @@ public final class com/apollographql/apollo/execution/FloatCoercing : com/apollo
5959
public final class com/apollographql/apollo/execution/GraphQLRequest {
6060
public final fun getDocument ()Ljava/lang/String;
6161
public final fun getExtensions ()Ljava/util/Map;
62+
public final fun getOnError ()Lcom/apollographql/apollo/execution/OnError;
6263
public final fun getOperationName ()Ljava/lang/String;
6364
public final fun getVariables ()Ljava/util/Map;
6465
}
@@ -70,11 +71,14 @@ public final class com/apollographql/apollo/execution/GraphQLRequest$Builder {
7071
public final fun extensions (Ljava/util/Map;)Lcom/apollographql/apollo/execution/GraphQLRequest$Builder;
7172
public final fun getDocument ()Ljava/lang/String;
7273
public final fun getExtensions ()Ljava/util/Map;
74+
public final fun getOnError ()Lcom/apollographql/apollo/execution/OnError;
7375
public final fun getOperationName ()Ljava/lang/String;
7476
public final fun getVariables ()Ljava/util/Map;
77+
public final fun onError (Lcom/apollographql/apollo/execution/OnError;)Lcom/apollographql/apollo/execution/GraphQLRequest$Builder;
7578
public final fun operationName (Ljava/lang/String;)Lcom/apollographql/apollo/execution/GraphQLRequest$Builder;
7679
public final fun setDocument (Ljava/lang/String;)V
7780
public final fun setExtensions (Ljava/util/Map;)V
81+
public final fun setOnError (Lcom/apollographql/apollo/execution/OnError;)V
7882
public final fun setOperationName (Ljava/lang/String;)V
7983
public final fun setVariables (Ljava/util/Map;)V
8084
public final fun variables (Ljava/util/Map;)Lcom/apollographql/apollo/execution/GraphQLRequest$Builder;
@@ -85,7 +89,6 @@ public final class com/apollographql/apollo/execution/GraphQLRequestKt {
8589
public static final fun parseAsGraphQLRequest (Ljava/util/Map;)Ljava/lang/Object;
8690
public static final fun parseAsGraphQLRequest (Lokio/BufferedSource;)Ljava/lang/Object;
8791
public static final fun toExternalValueMap (Ljava/util/Map;)Ljava/lang/Object;
88-
public static final fun toGraphQLRequest (Ljava/lang/String;)Lcom/apollographql/apollo/execution/GraphQLRequest;
8992
}
9093

9194
public final class com/apollographql/apollo/execution/GraphQLResponse {
@@ -140,6 +143,15 @@ public final class com/apollographql/apollo/execution/JsonCoercing : com/apollog
140143
public fun serialize (Ljava/lang/Object;)Ljava/lang/Object;
141144
}
142145

146+
public final class com/apollographql/apollo/execution/OnError : java/lang/Enum {
147+
public static final field HALT Lcom/apollographql/apollo/execution/OnError;
148+
public static final field NULL Lcom/apollographql/apollo/execution/OnError;
149+
public static final field PROPAGATE Lcom/apollographql/apollo/execution/OnError;
150+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
151+
public static fun valueOf (Ljava/lang/String;)Lcom/apollographql/apollo/execution/OnError;
152+
public static fun values ()[Lcom/apollographql/apollo/execution/OnError;
153+
}
154+
143155
public abstract interface class com/apollographql/apollo/execution/OperationCallback {
144156
public abstract fun onOperationCompleted (Lcom/apollographql/apollo/execution/GraphQLResponse;)Lcom/apollographql/apollo/execution/GraphQLResponse;
145157
}

0 commit comments

Comments
 (0)