Skip to content

Support multiple typeNames on @SchemaMapping and @BatchMapping #236

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

Conversation

francis-a
Copy link

GitHub issue: #235

This draft aims to provide a simple sketch for supporting multiple typeNames on mapping annotations. The use-case for why this may be a helpful inclusion set out in the attached issue.

@pivotal-cla
Copy link

@francis-a Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 23, 2021
@pivotal-cla
Copy link

@francis-a Thank you for signing the Contributor License Agreement!

@jord1e
Copy link
Contributor

jord1e commented Dec 23, 2021

typeNames seems unintuitive

DGS does not do this https://netflix.github.io/dgs/datafetching/#the-dgsdata-dgsquery-dgsmutation-and-dgssubscription-annotations

NestJS does not do this https://docs.nestjs.com/graphql/resolvers

I am also afraid of the added complexity and how tooling would implement this, GraphQL Java also does not implement such a feature

Adding a second SchemMapping is just a copy+paste action and also gives the added ability to use security optimally

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Feb 8, 2022

Sorry for the delayed response. I can't say I completely understand the scenario, nor why exactly it doesn't work, at least not without a sample to run.

That said, I can say we don't really want to change the annotation attributes to support a use case that's a bit difficult to explain, and may open up other unexpected possibilities. For a one-off case, declaring multiple @BatchMapping that delegate to the same internal method seems like a reasonable trade-off vs having everyone who looks at the annotations wonder what could multiple values be used for and why that's there.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Feb 8, 2022
@francis-a
Copy link
Author

Hi @rstoyanchev I totally understand your point. Let me try to describe my use-case a bit more in-case it's helpful. Generally using multiple mapping annotations does work and is a fair tradeoff.

Given the following Schema

interface User {
    username: String!

    "Populated on request, is expensive to calculate"
    expensiveField: String!
}

type UserTypeA implements User {
   ....
}

type UserTypeB implements User {
   ....
}

union BothUsers = UserTypeA | UserTypeB

type Query {
   userFind(username: String!): BothUsers!
}

To go along with this we have the following Kotlin model.

interface User {
   val username: String
   // no expensiveField on this interface, we don't want consumers of this object to need to populate this
}

// in the controller
    @QueryMapping(name = "userFind")
    fun userFind(
        @Argument(name = "username")
        username: String
    ): User {
       // ....
    }

   // here is where we need multiple mappings
   // this is because we need to map expensiveField to both UserTypeA and UserTypeB
    @BatchMapping(typeName = "UserTypeA", field = "expensiveField")
    fun batchUserTypeAexpensiveField(users: List<User>) = ....
    @BatchMapping(typeName = "UserTypeB", field = "expensiveField")
    fun batchUserTypeBexpensiveField(users: List<User>) = ....
 

Hopefully this example makes the use-case a bit more clear.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 15, 2022
@jord1e
Copy link
Contributor

jord1e commented Feb 15, 2022

How often does that realistically happen for it to warrant such a feature?

More importantly:
In the above example I don't really see a compelling use-case, why are you duplicating fields across types which share the same logic?

@rstoyanchev
Copy link
Contributor

I'm also not quite sure why it is a union when the two types already have a common parent interface.

In any case, thanks for elaborating. We'll leave at that for now. We can always reconsider if this gathers more interest or more uses cases emerge.

@rstoyanchev rstoyanchev added status: declined A suggestion or change that we don't feel we should currently apply and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Feb 16, 2022
@pinguinjkeke
Copy link

pinguinjkeke commented Mar 7, 2023

I'm also not quite sure why it is a union when the two types already have a common parent interface.

In any case, thanks for elaborating. We'll leave at that for now. We can always reconsider if this gathers more interest or more uses cases emerge.

We're facing the same issue in a large collection of interfaces.

Any workarounds?

@earandap
Copy link

We are encountering the same problem.

@adrian-skybaker
Copy link

How often does that realistically happen for it to warrant such a feature?

Pretty much anytime you use an interface in your GraphQL schema.

@rstoyanchev
Copy link
Contributor

This is now superseded by #871.

@rstoyanchev rstoyanchev added status: superseded Issue is superseded by another and removed status: declined A suggestion or change that we don't feel we should currently apply labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded Issue is superseded by another
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants