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

Camel case arguments are not working with Func plugin #63

Closed
DGolubets opened this issue Jun 23, 2023 · 3 comments
Closed

Camel case arguments are not working with Func plugin #63

DGolubets opened this issue Jun 23, 2023 · 3 comments

Comments

@DGolubets
Copy link

DGolubets commented Jun 23, 2023

Hi,

It seems that there is some inconsistency in arguments casing when using the Func plugin.

I use the following config:

projects:
  images:
    schema: ---
    documents: queries/*.graphql
    extensions:
      turms:
        out_dir: api
        plugins:
          - type: turms.plugins.enums.EnumsPlugin
          - type: turms.plugins.inputs.InputsPlugin
          - type: turms.plugins.fragments.FragmentsPlugin
          - type: turms.plugins.operations.OperationsPlugin
          - type: turms.plugins.funcs.FuncsPlugin
            global_args:
              - type: gql.client.AsyncClientSession
                key: client
            definitions:
              - type: query
                use: api.proxies.execute
                is_async: True
              - type: mutation
                use: api.proxies.execute
                is_async: True
        stylers:
          - type: turms.stylers.capitalize.CapitalizeStyler
          - type: turms.stylers.snake_case.SnakeCaseStyler
        scalar_definitions:
          ID: str
          Long: int
          Instant: datetime.datetime

I got this Arguments class generated:

class Arguments(BaseModel):
        user_id: str

But my query uses $userId.

@jhnnsrs
Copy link
Owner

jhnnsrs commented Jun 29, 2023

Hi there!

Thanks for the issue. I have just created a pull request that should fix this : #64 .

Arguments now automatically aliases arguments when the stylers version doesn't match the original field_name

Here:

class Arguments(BaseModel):
    user_id: str = Field(alias="userId")

As this may introduce some inconveniences when parsing arguments, this PR also introduce a new operations
plugin option:

- type: turms.plugins.operations.OperationsPlugin
  arguments_allow_population_by_field_name: True #default is false
class Arguments(BaseModel):
    user_id: str = Field(alias="userId")
    
    class Config:
       allow_population_by_field_name= True

Which allows population like this: "QueryName.Arguments(user_id=3)" on to op "QueryName.Arguments(userId=3)"

Feel this is not the smoothest solution though, any ideas on that?

@DGolubets
Copy link
Author

Hi!

Thank you for tackling this issue so quick.
This looks good.

What's the downside of having arguments_allow_population_by_field_name true by default?

@jhnnsrs
Copy link
Owner

jhnnsrs commented Sep 20, 2024

Hi @DGolubets, i am closing this issue now, which i should have done a while ago :D hope everything still works for you,
this should now be fixed in 0.6.0 that relies on pydantic v2 as well :)

@jhnnsrs jhnnsrs closed this as completed Sep 20, 2024
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