enisdenjo / graphql-sse

Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client.
https://the-guild.dev/graphql/sse
MIT License
384 stars 19 forks source link

Handler does not accept AST as a query #64

Closed ddiachkov closed 1 year ago

ddiachkov commented 1 year ago

Hello!

I use graphql-codegen to parse and pre-compile queries into AST (DocumentNode). When I send the query to the server as JSON, I get Invalid query error due to this check.

It looks like both parseReq and prepare are designed^1 to handle this properly. So I think this is a bug.

Expected behavior: no error; handler uses provided AST Current behavior: {"errors":[{"message":"Invalid query"}]}

Example cURL:

curl -v -X POST 'http://0.0.0.0:8000/graphql/kiosk/stream' -H 'accept: text/event-stream' -H 'Accept-Encoding: gzip' -H 'authorization: xxx' -H 'Connection: Keep-Alive' -H 'Content-Length: 505' -H 'Content-Type: application/json; charset=utf-8' -H 'Host: 0.0.0.0:8000' -H 'User-Agent: okhttp/5.0.0-alpha.11' -H 'x-snackpass-client: @snackpass/kiosk' -H 'x-snackpass-client-version: 32.5.0' -d '{"query":{"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"subscription","name":{"kind":"Name","value":"SubscribeToActiveOrders"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"activePurchases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"_id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"timestamp"}}]}}]}}]}}'