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 1 commit
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
@@ -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: |-
{
"errors": [
{
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
Copy link
Member Author

Choose a reason for hiding this comment

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

this error is coming from a "remove field" transform that we use for tests. I activated this transform with onCommentUpdated(id: ID): Comment @toBeDeleted directive in the overall schema

Copy link
Member Author

Choose a reason for hiding this comment

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

previously we would blow up with your data fetcher must return a publisher ... kind of an error

Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is an error from the introspection service? Why is the error message null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I clarified the error message on the RemoveFieldTransform to make it less confusing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see

}
}
],
"data": {
"commentsApi": null
}
}
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: |-
{
"errors": [
{
"locations": [],
"message": "null",
"extensions": {
"classification": "ValidationError"
}
}
],
"data": {
"onCommentUpdated": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "no introspections on subscriptions"
enabled: true
# language=GraphQL
overallSchema:
MyService: |
type Query {
comment: Comment
}
type Subscription {
onComment: Comment @namespaced
}
type Comment {
id: ID
}
# language=GraphQL
underlyingSchema:
MyService: |
type Query {
comment: Comment
}
type Subscription {
onComment: Comment
}
type Comment {
id: ID
}
# language=GraphQL
query: |
subscription {
__typename
}
variables: { }
serviceCalls: [ ]
# language=JSON
response: |-
{
"data": null,
"errors": [
{
"message": "Validation error (SubscriptionIntrospectionRootField) : Subscription operation 'null' root field '__typename' cannot be an introspection field",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"classification": "ValidationError"
}
}
]
}
Loading