strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations πŸ“
https://strawberry.rocks
MIT License
3.87k stars 511 forks source link

AttributeError when query passed is a list and not a dict #3398

Open Amangiri99 opened 5 months ago

Amangiri99 commented 5 months ago

While doing a testing my graphql endpoints, I came across an issue that if the query sent in the request is a list an attributeError is raised. On further investigation I found out when parsing the request data to GrahpqlRequestData we are accessing the data assuming it's a dict, rather we should validate it first if data is a valid dictionary

Describe the Bug

System Information

Additional Context

Upvote & Fund

Fund with Polar

patrick91 commented 5 months ago

Hi @Amangiri99 can you add a reproduction? 😊 thanks!

Amangiri99 commented 5 months ago

Hit any of the graphql endpoints, by sending a query. The query shouldn't be a dict rather a list. Example: --data β€œ[{\”query\":\"{something(id:\\"examples\\"){getSomething{Some}}}\”}]” \

Also I got this error while making request using curl command.

patrick91 commented 5 months ago

@Amangiri99 how come you're sending a list? usually that's done when you want to run multiple operations (like batching)

Amangiri99 commented 5 months ago

@patrick91 It's just a random error, that I came across while doing a peneration testing of my application. Also we won't be able to send a list from postman or graphql ide. This can only be sent using curl request

patrick91 commented 5 months ago

@Amangiri99 yeah, but you could send a list using things like https://www.apollographql.com/docs/react/api/link/apollo-link-batch-http/

I don't think we should worry about lists with single items for now (batching will help with that), but maybe we can improve the error?

Amangiri99 commented 5 months ago

@patrick91 Right, we should improve the error. We should send a generic error if a list is received instead of object.