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 alias for Resolver Functions' Param #3029

Closed
1 of 3 tasks
maacck opened this issue Aug 11, 2023 · 2 comments
Closed
1 of 3 tasks

Allow alias for Resolver Functions' Param #3029

maacck opened this issue Aug 11, 2023 · 2 comments

Comments

@maacck
Copy link

maacck commented Aug 11, 2023

Provide "alias" ability to resolver functions' param.

Something like FastAPI

async def example_resolver( _id: strawberry.Param(..., alias="id")) -> Res:
    ....

Feature Request Type

  • Core functionality
  • Alteration (enhancement/optimization) of existing feature(s)
  • New behavior

Description

Since GraphQL commonly using name "input" for mutation, and "input" is bultin function in python. It will be better if we could find a way to use "alias" and also fit both Python and GraphQL naming convention.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@maacck maacck changed the title Allow alias for Allow alias for Resolver Functions' Param Aug 11, 2023
@patrick91
Copy link
Member

hi @maacck! that's already possible with strawberry.argument, see: https://play.strawberry.rocks/?gist=433579242535b6715dd0e4b95f24c878

import strawberry

from typing import Annotated

@strawberry.type
class User:
    name: str
    age: int

@strawberry.type
class Query:
    @strawberry.field
    def user(self, input_: Annotated[str, strawberry.argument(name="input")]) -> User:
        return User(name="Patrick", age=100)

schema = strawberry.Schema(query=Query)

This should be documented though!

@maacck
Copy link
Author

maacck commented Aug 18, 2023

Aha, Thanks you @patrick91 . It works now.
I actually have tried to use strawberry.arugment before, but somehow it didn't work. And this should definitely be documented

@maacck maacck closed this as completed Aug 18, 2023
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

No branches or pull requests

2 participants