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

GraphQLTransportWS: Always return an id upon errors #1845

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

SvenW
Copy link
Contributor

@SvenW SvenW commented Aug 21, 2023

Fixes #1844

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok to me.

@paulpdaniels wanna take a look?

@kyri-petrou
Copy link
Collaborator

kyri-petrou commented Aug 22, 2023

Seems ok to me too. Do we also need to fix this for the legacy protocol too, or is the spec different for that one?

@SvenW
Copy link
Contributor Author

SvenW commented Aug 22, 2023

Seems ok to me too. Do we also need to fix this for the legacy protocol too, or is the spec different for that one?

From what I can tell connection errors do not include the id in the old spec

@kyri-petrou
Copy link
Collaborator

@SvenW the error you referred to in the new spec is a response to the Subscribe message, not to the connection message.

image

This is the equivalent of GQL_ERROR in the legacy spec: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_error

I can't seem to find anywhere how an error due to connection is meant to look like though in the new spec

@kyri-petrou
Copy link
Collaborator

According to the spec, it seems that we need to use HTTP codes to reject connection_init messages

If the server wishes to reject the connection, for example during authentication, it is recommended to close the socket with 4403: Forbidden.

https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#connectioninit

@SvenW
Copy link
Contributor Author

SvenW commented Aug 22, 2023

According to the spec, it seems that we need to use HTTP codes to reject connection_init messages

If the server wishes to reject the connection, for example during authentication, it is recommended to close the socket with 4403: Forbidden.

https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#connectioninit

Yeah, you're right. We need to handle the authentication errors for the connection_init events as well with the correct code when closing the socket. However from what I can tell the error message should always contain the id though.

@kyri-petrou
Copy link
Collaborator

@SvenW I agree, although I don't think this will solve the linked issue. Or have you tested and it does solve it?

@SvenW
Copy link
Contributor Author

SvenW commented Aug 22, 2023

@SvenW I agree, although I don't think this will solve the linked issue. Or have you tested and it does solve it?

Well it solves it but not completely according to the spec. Let me see if I can find some time during the day and solve the unauthenticated part as well

@SvenW
Copy link
Contributor Author

SvenW commented Aug 22, 2023

@SvenW I agree, although I don't think this will solve the linked issue. Or have you tested and it does solve it?

From what I can tell graphql-transport-ws always closes the socket on connection_init with a 4403, Forbidden as can be seen here. What do you think @kyri-petrou ?

@SvenW SvenW changed the title Always return an id upon errors GraphQLTransportWS: Always return an id upon errors Aug 22, 2023
override def error[E](id: Option[String], e: E): GraphQLWSOutput =
override def error[E](id: Option[String], e: E): GraphQLWSOutput = {
val outputId = id match {
case None => Some(UUID.randomUUID().toString)
Copy link
Collaborator

@paulpdaniels paulpdaniels Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It would be better to use the zio.Random construct, though you'll then need to push the id generation up where you will still be in ZIO land

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SvenW can you just update that one? Then it's good to go 🙏

@kyri-petrou
Copy link
Collaborator

From what I can tell graphql-transport-ws always closes the socket on connection_init with a 4403, Forbidden as can be seen here. What do you think @kyri-petrou ?

I think as long as we're within the spec and it works that's fine. Have you tested whether this solves the original issue?

@SvenW
Copy link
Contributor Author

SvenW commented Aug 23, 2023

From what I can tell graphql-transport-ws always closes the socket on connection_init with a 4403, Forbidden as can be seen here. What do you think @kyri-petrou ?

I think as long as we're within the spec and it works that's fine. Have you tested whether this solves the original issue?

I've tested it with the AuthExampleApp and it seems to behave as expected, both with error messages and with the connection_init event with authorization errors.

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@SvenW SvenW force-pushed the fix/graphql-transport-ws-init branch from fa8d11c to 8af118f Compare August 25, 2023 08:32
@ghostdogpr ghostdogpr merged commit 85d2352 into ghostdogpr:series/2.x Aug 29, 2023
@SvenW SvenW deleted the fix/graphql-transport-ws-init branch August 29, 2023 12:26
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

Successfully merging this pull request may close these issues.

ConnectionInit in GraphQLTransportWS returns faulty message upon error
4 participants