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

Improve type resolving #122

Closed
Maximilien-R opened this issue Feb 12, 2019 · 1 comment · Fixed by #272
Closed

Improve type resolving #122

Maximilien-R opened this issue Feb 12, 2019 · 1 comment · Fixed by #272
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@Maximilien-R
Copy link
Member

Since tartiflette allow us to deal only with dict. Resolving the __typename field for an UnionType is difficult and is delegate to the Resolver implementation which need to return the __typename in the resolved value.

Maybe we could add an optional resolve_type argument to the Resolver decorator which could take a callable in charge of determining the __typename to return for the resolved value? This resolve_type parameter could be required for an UnionType resolver which returns a value where the __typename couldn't be resolved by the default resolve_type function (a dict without a __typename key for instance).

@Resolver(
    "Query.catOrDog",
    resolve_type=lambda result: "Dog" if is_dog(result) else "Cat",
)
def query_cat_or_dog_resolver(*_args, **_kwargs):
    return {
        "name": "Dogo",
    }
@Maximilien-R Maximilien-R added enhancement New feature or request question Further information is requested labels Feb 12, 2019
@Maximilien-R Maximilien-R added this to the road-to-v1 milestone Feb 13, 2019
@abusi
Copy link
Contributor

abusi commented Mar 14, 2019

I kind of like this idea @Maximilien-R.
@tsunammis what do you think of this idea?

I think it's great to enable our users to override the current default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants