Skip to content

Commit 8a5e1b4

Browse files
authored
return empty response when subscription are running on the internal introspection service (#649)
* return empty response when subscription are running on the internal introspection service * add RemoveFieldTestTransform error message
1 parent 94bbf14 commit 8a5e1b4

14 files changed

Lines changed: 245 additions & 63 deletions

lib/src/main/java/graphql/nadel/engine/blueprint/IntrospectionService.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import graphql.ExecutionInput
44
import graphql.GraphQL
55
import graphql.GraphqlErrorHelper.toSpecification
66
import graphql.language.AstPrinter
7+
import graphql.language.OperationDefinition
78
import graphql.nadel.NadelDefinitionRegistry
9+
import graphql.nadel.NadelServiceExecutionResultImpl
810
import graphql.nadel.Service
911
import graphql.nadel.ServiceExecution
1012
import graphql.nadel.ServiceExecutionParameters
1113
import graphql.nadel.ServiceExecutionResult
12-
import graphql.nadel.NadelServiceExecutionResultImpl
1314
import graphql.nadel.engine.util.makeFieldCoordinates
1415
import graphql.nadel.engine.util.toBuilder
1516
import graphql.nadel.engine.util.toBuilderWithoutTypes
@@ -40,6 +41,9 @@ open class NadelDefaultIntrospectionRunner(schema: GraphQLSchema) : ServiceExecu
4041
.build()
4142

4243
override fun execute(serviceExecutionParameters: ServiceExecutionParameters): CompletableFuture<ServiceExecutionResult> {
44+
if (serviceExecutionParameters.operationDefinition.operation == OperationDefinition.Operation.SUBSCRIPTION) {
45+
return CompletableFuture.completedFuture(NadelServiceExecutionResultImpl())
46+
}
4347
return graphQL
4448
.executeAsync(
4549
ExecutionInput.newExecutionInput()

test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ class `top-level-field-is-removed` : EngineTestHook {
101101
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
102102
}
103103

104+
@UseHook
105+
class `top-level-field-is-removed-for-a-subscription` : EngineTestHook {
106+
override val customTransforms = listOf(RemoveFieldTestTransform())
107+
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
108+
}
109+
110+
@UseHook
111+
class `top-level-field-is-removed-for-a-subscription-with-namespaced-field` : EngineTestHook {
112+
override val customTransforms = listOf(RemoveFieldTestTransform())
113+
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
114+
}
115+
104116
@UseHook
105117
class `top-level-field-is-removed-hint-is-off` : EngineTestHook {
106118
override val customTransforms = listOf(RemoveFieldTestTransform())

test/src/test/kotlin/graphql/nadel/tests/transforms/RemoveFieldTestTransform.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql.nadel.tests.transforms
22

3+
import graphql.ErrorType
34
import graphql.GraphQLError
45
import graphql.introspection.Introspection
56
import graphql.nadel.Service
@@ -15,11 +16,10 @@ import graphql.nadel.engine.transform.query.NadelQueryTransformer
1516
import graphql.nadel.engine.transform.result.NadelResultInstruction
1617
import graphql.nadel.engine.transform.result.NadelResultKey
1718
import graphql.nadel.engine.transform.result.json.JsonNodes
19+
import graphql.nadel.engine.util.newGraphQLError
1820
import graphql.nadel.engine.util.queryPath
1921
import graphql.normalized.ExecutableNormalizedField
2022
import graphql.schema.GraphQLObjectType
21-
import graphql.validation.ValidationError.newValidationError
22-
import graphql.validation.ValidationErrorType
2323

2424
class RemoveFieldTestTransform : NadelTransform<GraphQLError> {
2525
override suspend fun isApplicable(
@@ -40,7 +40,10 @@ class RemoveFieldTestTransform : NadelTransform<GraphQLError> {
4040
?: return null
4141

4242
if (objectType.getField(overallField.name)?.getDirective("toBeDeleted") != null) {
43-
return newValidationError().validationErrorType(ValidationErrorType.WrongType).build()
43+
return newGraphQLError(
44+
"field `${objectType.name}.${overallField.name}` has been removed by RemoveFieldTestTransform",
45+
ErrorType.DataFetchingException,
46+
)
4447
}
4548

4649
return null

test/src/test/resources/fixtures/chained transforms/two-transforms-on-a-field.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ response: |-
7777
},
7878
"errors": [
7979
{
80-
"message": "null",
80+
"message": "field `Foo.epicEntity` has been removed by RemoveFieldTestTransform",
8181
"locations": [],
8282
"extensions": {
83-
"classification": "ValidationError"
83+
"classification": "DataFetchingException"
8484
}
8585
}
86-
],
87-
"extensions": {}
86+
]
8887
}

test/src/test/resources/fixtures/field removed/hidden-namespaced-hydration-top-level-field-is-removed.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ serviceCalls:
9191
# language=JSON
9292
response: |-
9393
{
94+
"data": {
95+
"issueById": {
96+
"id": "C1",
97+
"comment": null
98+
}
99+
},
94100
"errors": [
95101
{
102+
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
96103
"locations": [],
97-
"message": "An error has occurred",
98104
"extensions": {
99-
"classification": "ValidationError"
105+
"classification": "DataFetchingException"
100106
}
101107
}
102-
],
103-
"data": {
104-
"issueById": {
105-
"id": "C1",
106-
"comment": null
107-
}
108-
}
108+
]
109109
}

test/src/test/resources/fixtures/field removed/hydration-top-level-field-is-removed.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ serviceCalls:
8080
# language=JSON
8181
response: |-
8282
{
83+
"data": {
84+
"issueById": {
85+
"id": "C1",
86+
"comment": null
87+
}
88+
},
8389
"errors": [
8490
{
91+
"message": "field `Query.commentById` has been removed by RemoveFieldTestTransform",
8592
"locations": [],
86-
"message": "An error has occurred",
8793
"extensions": {
88-
"classification": "ValidationError"
94+
"classification": "DataFetchingException"
8995
}
9096
}
91-
],
92-
"data": {
93-
"issueById": {
94-
"id": "C1",
95-
"comment": null
96-
}
97-
}
97+
]
9898
}

test/src/test/resources/fixtures/field removed/namespaced-field-is-removed-with-renames.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ serviceCalls: [ ]
4040
# language=JSON
4141
response: |-
4242
{
43+
"data": {
44+
"commentApi": {
45+
"commentById": null
46+
}
47+
},
4348
"errors": [
4449
{
50+
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
4551
"locations": [],
46-
"message": "null",
4752
"extensions": {
48-
"classification": "ValidationError"
53+
"classification": "DataFetchingException"
4954
}
5055
}
51-
],
52-
"data": {
53-
"commentApi": {
54-
"commentById": null
55-
}
56-
}
56+
]
5757
}

test/src/test/resources/fixtures/field removed/namespaced-field-is-removed.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ serviceCalls: [ ]
4040
# language=JSON
4141
response: |-
4242
{
43+
"data": {
44+
"commentApi": {
45+
"commentById": null
46+
}
47+
},
4348
"errors": [
4449
{
50+
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
4551
"locations": [],
46-
"message": "null",
4752
"extensions": {
48-
"classification": "ValidationError"
53+
"classification": "DataFetchingException"
4954
}
5055
}
51-
],
52-
"data": {
53-
"commentApi": {
54-
"commentById": null
55-
}
56-
}
56+
]
5757
}

test/src/test/resources/fixtures/field removed/namespaced-hydration-top-level-field-is-removed.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ serviceCalls:
8787
# language=JSON
8888
response: |-
8989
{
90+
"data": {
91+
"issueById": {
92+
"id": "C1",
93+
"comment": null
94+
}
95+
},
9096
"errors": [
9197
{
98+
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
9299
"locations": [],
93-
"message": "An error has occurred",
94100
"extensions": {
95-
"classification": "ValidationError"
101+
"classification": "DataFetchingException"
96102
}
97103
}
98-
],
99-
"data": {
100-
"issueById": {
101-
"id": "C1",
102-
"comment": null
103-
}
104-
}
104+
]
105105
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "top level field is removed for a subscription with namespaced field"
2+
enabled: true
3+
# language=GraphQL
4+
overallSchema:
5+
CommentService: |
6+
directive @toBeDeleted on FIELD_DEFINITION
7+
type Query {
8+
commentById(id: ID): Comment @toBeDeleted
9+
}
10+
type Subscription {
11+
commentsApi: CommentsApi @namespaced
12+
}
13+
type CommentsApi {
14+
onCommentUpdated(id: ID): Comment @toBeDeleted
15+
}
16+
type Comment {
17+
id: ID
18+
}
19+
# language=GraphQL
20+
underlyingSchema:
21+
CommentService: |
22+
type Query {
23+
commentById(id: ID): Comment
24+
}
25+
type Subscription {
26+
commentsApi: CommentsApi
27+
}
28+
type CommentsApi {
29+
onCommentUpdated(id: ID): Comment
30+
}
31+
type Comment {
32+
id: ID
33+
}
34+
# language=GraphQL
35+
query: |
36+
subscription {
37+
commentsApi {
38+
onCommentUpdated(id: "C1") {
39+
id
40+
}
41+
}
42+
}
43+
variables: { }
44+
serviceCalls: [ ]
45+
# language=JSON
46+
response: |-
47+
{
48+
"data": {
49+
"commentsApi": null
50+
},
51+
"errors": [
52+
{
53+
"message": "field `CommentsApi.onCommentUpdated` has been removed by RemoveFieldTestTransform",
54+
"locations": [],
55+
"extensions": {
56+
"classification": "DataFetchingException"
57+
}
58+
}
59+
]
60+
}

0 commit comments

Comments
 (0)