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

Bug: GraphQL spec does not mandate that "data" is always returned #240

Closed
twavv opened this issue Nov 16, 2023 · 4 comments · Fixed by #248
Closed

Bug: GraphQL spec does not mandate that "data" is always returned #240

twavv opened this issue Nov 16, 2023 · 4 comments · Fixed by #248

Comments

@twavv
Copy link

twavv commented Nov 16, 2023

This codebase assumes that the data key must always be present in the result. This is not the case according to the GraphQL spec: https://spec.graphql.org/October2021/#sec-Response-Format. If a query couldn't be executed (e.g., due to failing authentication on some servers), it will not include a data field -- only errors.

Consequently, this library doesn't handle that and will instead raise GraphQlClientInvalidResponseError.

@rafalp
Copy link
Contributor

rafalp commented Nov 16, 2023

What is expected behavior if data is not present here? Only solution that comes to mind would be setting error response as attribute on GraphQlClientInvalidResponseError for people to do whatever makes sense in their project.

@mat-sop
Copy link
Contributor

mat-sop commented Nov 16, 2023

@rafalp
Copy link
Contributor

rafalp commented Nov 16, 2023

Oh, you are right! Then I don't know what else could we do here.

@twavv
Copy link
Author

twavv commented Nov 16, 2023

I think ideally raising GraphQLClientGraphQLMultiError would be the right™ choice since that's the way this library surfaces anything in the errors response. It might require changing the type of data there to be Optional[Dict[str, Any]].

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