Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return empty response when subscription are running on the internal introspection service #649

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import graphql.ExecutionInput
import graphql.GraphQL
import graphql.GraphqlErrorHelper.toSpecification
import graphql.language.AstPrinter
import graphql.language.OperationDefinition
import graphql.nadel.NadelDefinitionRegistry
import graphql.nadel.NadelServiceExecutionResultImpl
import graphql.nadel.Service
import graphql.nadel.ServiceExecution
import graphql.nadel.ServiceExecutionParameters
import graphql.nadel.ServiceExecutionResult
import graphql.nadel.NadelServiceExecutionResultImpl
import graphql.nadel.engine.util.makeFieldCoordinates
import graphql.nadel.engine.util.toBuilder
import graphql.nadel.engine.util.toBuilderWithoutTypes
Expand Down Expand Up @@ -40,6 +41,9 @@ open class NadelDefaultIntrospectionRunner(schema: GraphQLSchema) : ServiceExecu
.build()

override fun execute(serviceExecutionParameters: ServiceExecutionParameters): CompletableFuture<ServiceExecutionResult> {
if (serviceExecutionParameters.operationDefinition.operation == OperationDefinition.Operation.SUBSCRIPTION) {
return CompletableFuture.completedFuture(NadelServiceExecutionResultImpl())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just empty result?

}
return graphQL
.executeAsync(
ExecutionInput.newExecutionInput()
Expand Down
12 changes: 12 additions & 0 deletions test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ class `top-level-field-is-removed` : EngineTestHook {
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
}

@UseHook
class `top-level-field-is-removed-for-a-subscription` : EngineTestHook {
override val customTransforms = listOf(RemoveFieldTestTransform())
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
}

@UseHook
class `top-level-field-is-removed-for-a-subscription-with-namespaced-field` : EngineTestHook {
override val customTransforms = listOf(RemoveFieldTestTransform())
override fun makeExecutionHints(builder: NadelExecutionHints.Builder) = builder.shortCircuitEmptyQuery { true }
}

@UseHook
class `top-level-field-is-removed-hint-is-off` : EngineTestHook {
override val customTransforms = listOf(RemoveFieldTestTransform())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.nadel.tests.transforms

import graphql.ErrorType
import graphql.GraphQLError
import graphql.introspection.Introspection
import graphql.nadel.Service
Expand All @@ -15,11 +16,10 @@ import graphql.nadel.engine.transform.query.NadelQueryTransformer
import graphql.nadel.engine.transform.result.NadelResultInstruction
import graphql.nadel.engine.transform.result.NadelResultKey
import graphql.nadel.engine.transform.result.json.JsonNodes
import graphql.nadel.engine.util.newGraphQLError
import graphql.nadel.engine.util.queryPath
import graphql.normalized.ExecutableNormalizedField
import graphql.schema.GraphQLObjectType
import graphql.validation.ValidationError.newValidationError
import graphql.validation.ValidationErrorType

class RemoveFieldTestTransform : NadelTransform<GraphQLError> {
override suspend fun isApplicable(
Expand All @@ -40,7 +40,10 @@ class RemoveFieldTestTransform : NadelTransform<GraphQLError> {
?: return null

if (objectType.getField(overallField.name)?.getDirective("toBeDeleted") != null) {
return newValidationError().validationErrorType(ValidationErrorType.WrongType).build()
return newGraphQLError(
"field `${objectType.name}.${overallField.name}` has been removed by RemoveFieldTestTransform",
ErrorType.DataFetchingException,
)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ response: |-
},
"errors": [
{
"message": "null",
"message": "field `Foo.epicEntity` has been removed by RemoveFieldTestTransform",
"locations": [],
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"extensions": {}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ serviceCalls:
# language=JSON
response: |-
{
"data": {
"issueById": {
"id": "C1",
"comment": null
}
},
"errors": [
{
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "An error has occurred",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"issueById": {
"id": "C1",
"comment": null
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ serviceCalls:
# language=JSON
response: |-
{
"data": {
"issueById": {
"id": "C1",
"comment": null
}
},
"errors": [
{
"message": "field `Query.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "An error has occurred",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"issueById": {
"id": "C1",
"comment": null
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ serviceCalls: [ ]
# language=JSON
response: |-
{
"data": {
"commentApi": {
"commentById": null
}
},
"errors": [
{
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"commentApi": {
"commentById": null
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ serviceCalls: [ ]
# language=JSON
response: |-
{
"data": {
"commentApi": {
"commentById": null
}
},
"errors": [
{
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"commentApi": {
"commentById": null
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ serviceCalls:
# language=JSON
response: |-
{
"data": {
"issueById": {
"id": "C1",
"comment": null
}
},
"errors": [
{
"message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "An error has occurred",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"issueById": {
"id": "C1",
"comment": null
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "top level field is removed for a subscription with namespaced field"
enabled: true
# language=GraphQL
overallSchema:
CommentService: |
directive @toBeDeleted on FIELD_DEFINITION
type Query {
commentById(id: ID): Comment @toBeDeleted
}
type Subscription {
commentsApi: CommentsApi @namespaced
}
type CommentsApi {
onCommentUpdated(id: ID): Comment @toBeDeleted
}
type Comment {
id: ID
}
# language=GraphQL
underlyingSchema:
CommentService: |
type Query {
commentById(id: ID): Comment
}
type Subscription {
commentsApi: CommentsApi
}
type CommentsApi {
onCommentUpdated(id: ID): Comment
}
type Comment {
id: ID
}
# language=GraphQL
query: |
subscription {
commentsApi {
onCommentUpdated(id: "C1") {
id
}
}
}
variables: { }
serviceCalls: [ ]
# language=JSON
response: |-
{
"data": {
"commentsApi": null
},
"errors": [
{
"message": "field `CommentsApi.onCommentUpdated` has been removed by RemoveFieldTestTransform",
"locations": [],
"extensions": {
"classification": "DataFetchingException"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "top level field is removed for a subscription"
enabled: true
# language=GraphQL
overallSchema:
CommentService: |
directive @toBeDeleted on FIELD_DEFINITION
type Query {
commentById(id: ID): Comment
}
type Subscription {
onCommentUpdated(id: ID): Comment @toBeDeleted
}
type Comment {
id: ID
}
# language=GraphQL
underlyingSchema:
CommentService: |
type Query {
commentById(id: ID): Comment
}
type Subscription {
onCommentUpdated(id: ID): Comment
}
type Comment {
id: ID
}
# language=GraphQL
query: |
subscription {
onCommentUpdated(id: "C1") {
id
}
}
variables: { }
serviceCalls: [ ]
# language=JSON
response: |-
{
"data": {
"onCommentUpdated": null
},
"errors": [
{
"message": "field `Subscription.onCommentUpdated` has been removed by RemoveFieldTestTransform",
"locations": [],
"extensions": {
"classification": "DataFetchingException"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ serviceCalls:
# language=JSON
response: |-
{
"data": {
"commentById": null
},
"errors": [
{
"message": "field `Query.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"commentById": null
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ serviceCalls: [ ]
# language=JSON
response: |-
{
"data": {
"commentById": null
},
"errors": [
{
"message": "field `Query.commentById` has been removed by RemoveFieldTestTransform",
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
"classification": "DataFetchingException"
}
}
],
"data": {
"commentById": null
}
]
}
Loading
Loading