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

Allow using tuple (and/or iterable) as an alias to the GraphQL type #2035

Closed
dogweather opened this issue Jul 21, 2022 · 5 comments · Fixed by #2164
Closed

Allow using tuple (and/or iterable) as an alias to the GraphQL type #2035

dogweather opened this issue Jul 21, 2022 · 5 comments · Fixed by #2164

Comments

@dogweather
Copy link

dogweather commented Jul 21, 2022

Feature Request Type

Alteration (enhancement/optimization) of existing feature(s)

Description

Returning a tuple when the attribute is hinted as list works.

But hinting the return type correctly as a tuple causes an error:

@strawberry.type
class Dictionary:
    entries: tuple[Entry]
    sources: tuple[Source]
TypeError: Unexpected type tuple[Entry]

Our code uses tuples and iterables whenever appropriate for robustness, efficiency, and documentation. We also use strict type hinting. It'd be great for these read-only sequences to be explicitly supported.

@lonelyteapot
Copy link
Contributor

I think that a more general Sequence annotation makes sense.

jkimbo added a commit that referenced this issue Sep 12, 2022
To help with typing resolvers correctly, this PR updates the logic to
determine if an annotation is GraphQL List type by checking against the
Tuple and Sequence types.

Fixes #2035 and #2161

Diff-Id: e22a7
jkimbo added a commit that referenced this issue Sep 12, 2022
To help with typing resolvers correctly, this PR updates the logic to
determine if an annotation is GraphQL List type by checking against the
Tuple and Sequence types.

Fixes #2035 and #2161

Diff-Id: e22a7
patrick91 pushed a commit that referenced this issue Sep 12, 2022
* Convert Tuple and Sequence types to GraphQL List types

To help with typing resolvers correctly, this PR updates the logic to
determine if an annotation is GraphQL List type by checking against the
Tuple and Sequence types.

Fixes #2035 and #2161

Diff-Id: e22a7

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@jkimbo
Copy link
Member

jkimbo commented Sep 12, 2022

Support added in v0.130.0

@dperetti
Copy link

However, if the tuple is Tuple[Date, float] for instance, and it will yield a wrong type!

@patrick91
Copy link
Member

@dperetti good catch! I think in this case we should probably throw an error, what do you think?

@dperetti
Copy link

@patrick91 yeah, along with a reminder that GraphQL doesn't support tuples anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants