Skip to content

TypeMismatchError not reported for Subscription result #2609

Closed

Description

@rstoyanchev

If there is a type mismatch for the value on a subscription, the result comes back with null values and no errors. For example, here "greetings" is [String] but the DataFetcher returns String:

@Test
void subscription() throws Exception {
	String query = "subscription Greeting { greetings }";
	String schema = "type Subscription { greetings: [String] } type Query { greeting: String }";

	RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring()
			.type("Subscription", builder -> builder.dataFetcher("greetings", env -> Flux.just("hi", "hiya")))
			.build();

	GraphQLSchema graphQLSchema = new SchemaGenerator().makeExecutableSchema(new SchemaParser().parse(schema), wiring);
	GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();

	ExecutionResult result = graphQL.executeAsync(ExecutionInput.newExecutionInput(query).build()).get();
	System.out.println("Errors: " + result.getErrors());

	CountDownLatch latch = new CountDownLatch(1);
	result.<Publisher<ExecutionResult>>getData()
			.subscribe(new Subscriber<ExecutionResult>() {

				@Override
				public void onSubscribe(Subscription subscription) {
					subscription.request(Long.MAX_VALUE);
				}

				@Override
				public void onNext(ExecutionResult result) {
					System.out.println("Errors: " + result.getErrors() + ", Data: " + result.getData());
				}

				@Override
				public void onError(Throwable ex) {
					System.out.println("[onError]: " + ex);
				}

				@Override
				public void onComplete() {
					latch.countDown();
				}
			});
	
	latch.await();
}

The output is:

Errors: []
Errors: [], Data: {greetings=null}
Errors: [], Data: {greetings=null}

By comparison, for a regular query the same is reported as a TypeMismatchError:

@Test
void query() throws Exception {
	String query = "{ greeting }";
	String schema = "type Query { greeting: [String] }";

	RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring()
			.type("Query", builder -> builder.dataFetcher("greeting", env -> "hi"))
			.build();

	GraphQLSchema graphQLSchema = new SchemaGenerator().makeExecutableSchema(new SchemaParser().parse(schema), wiring);
	GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();

	ExecutionResult result = graphQL.executeAsync(ExecutionInput.newExecutionInput(query).build()).get();
	System.out.println("Errors: " + result.getErrors());
	System.out.println("Data: " + result.getData());
}

The output is:

Errors: [TypeMismatchError{path=[greeting], expectedType=[String]}]
Data: {greeting=null}

Not sure if this is expected behavior or not, but the error seems to be silently absorbed, not even TRACE logging shows anything.

Activity

  1. added a commit that references this issue on Nov 13, 2021
    0d52319
  2. added a commit that references this issue on Dec 6, 2021
    e388876
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions