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

[Question] How to render query with no fields selection? #8

Closed
Mukhametvaleev opened this issue Feb 21, 2023 · 2 comments
Closed

[Question] How to render query with no fields selection? #8

Mukhametvaleev opened this issue Feb 21, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Mukhametvaleev
Copy link

Mukhametvaleev commented Feb 21, 2023

How to render a valid GraphQL query with no fields kwarg?

query = Query(
    name='resetPassword',
    arguments=[
        Argument(
            name='userId',
            value=user_id,
        ),
        Argument(
            name='confirmationId',
            value=confirmation_id,
        ),
        Argument(
            name='password',
            value=password,
        ),
        Argument(
            name='passwordConfirm',
            value=password_confirm,
        ),
    ],
)

operation = Operation(
    type='mutation',
    name='ResetPassword',
    queries=[query],
)

print(operation.render())

Actual query:

mutation ResetPassword {
  resetPassword(
    userId: "69fa0d2e-f7e8-410c-be50-24a03804cb4c"
    confirmationId: "63f65921-66cf-400a-aa05-71446b3621d2"
    password: "87654321"
    passwordConfirm: "87654321"
  ) {
  }
}

Expected query:

mutation ResetPassword {
  resetPassword(
    userId: "69fa0d2e-f7e8-410c-be50-24a03804cb4c"
    confirmationId: "63f65921-66cf-400a-aa05-71446b3621d2"
    password: "87654321"
    passwordConfirm: "87654321"
  )
}
@Mukhametvaleev Mukhametvaleev changed the title [Question] How to render query with no field selection? [Question] How to render query with no fields selection? Feb 21, 2023
@denisart denisart self-assigned this Feb 21, 2023
@denisart
Copy link
Owner

denisart commented Feb 21, 2023

Hello, thank for your question!

The graphql-query does not currently support an empty list of response fields. The graphql-query will always add {...} to query`s body. It is a bug.

You can to correct your request to

query = Query(
    name='resetPassword',
    typename=True,
    arguments=[
        Argument(
            name='userId',
            value=user_id,
        ),
        Argument(
            name='confirmationId',
            value=confirmation_id,
        ),
        Argument(
            name='password',
            value=password,
        ),
        Argument(
            name='passwordConfirm',
            value=password_confirm,
        ),
    ],
)

operation = Operation(
    type='mutation',
    name='ResetPassword',
    queries=[query],
)

print(operation.render())

and don't process the result. I will fix this problem soon.

@denisart denisart added the bug Something isn't working label Feb 21, 2023
denisart pushed a commit that referenced this issue Mar 2, 2023
@denisart
Copy link
Owner

denisart commented Mar 2, 2023

Fixed in #9

@denisart denisart closed this as completed Mar 2, 2023
@denisart denisart assigned Naggertooth and denisart and unassigned denisart Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants