Skip to content

Improve type-safety of resolvers and publishers #492

@stuebingerb

Description

@stuebingerb

Consider the following (existing) test case (simplified):

fun newSchema() = defaultSchema {
    val publisher = mutation("createActor") {
        resolver { name: String -> Actor(name, 11) }
    }

    subscription("subscriptionActress") {
        resolver { subscription: String ->
            subscribe(subscription, publisher, Actress()) {
                subscriptionResult = it
            }
        }
    }
}


@Test
fun `Subscription return type must be the same as the publisher's`() {
    val exception = shouldThrowExactly<ExecutionException> {
        newSchema().executeBlocking("subscription {subscriptionActress(subscription : \"mySubscription\"){age}}")
    }
    exception.originalError shouldBeInstanceOf SchemaException::class
    exception shouldHaveMessage "Subscription return type must be the same as the publisher's"
}

"subscriptionActress" is defined as subscription for publisher (returning an Actor) but claims to return an Actress.

Problem:
The subscription's return type is obviously incorrect but only fails during execution of that subscription.

Target:
Creating such a schema must fail during schema creation latest. Ideally, it would not even compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions