1

I provided a GraphQL interface with Smallrye Graphql in Quarkus with a query and a subscription:

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;
import io.quarkus.security.Authenticated;
import io.smallrye.graphql.api.Subscription;
...

@GraphQLApi
@Authenticated
public class MyGraphQL {
   @Query(getInformation)
   public List<MyInformation> getMyInformation(int id) { ... }

   @Subscription(informationStream)
   public Multi<MyInformation> getMyInformationStream() { ... }
}

If I try to run the application and call the query using the integrated graphql-ui of Quarkus everyting works quite well if I add the Authorization Header

Query

query getInformation {
   getInformation(id: 1) {
     ....
   }

Header

{
  "Authorization": "Bearer <token>"
}

Now I try to do the same with the subscription: Subscription

subscription informationStream {
   informationStream() {
      ...
   }
}

And I also added the same Header:

{
  "Authorization": "Bearer <token>"
}

Unfortunately for the subscription I get an error message:

{
  "errors": [
    {
      "message": "System error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "informationStream"
      ],
      "extensions": {
        "code": "unauthorized"
      }
    }
  ]
}

How can I authenticate correctly using against this subscription?

1 Answer 1

0

It turned out that the problem is not in the authorization of the GraphQL-Backend but rather in GraphQL-UI. If you connect with a regular client (like https://github.com/graphql-python/gql/blob/master/docs/code_examples/websockets_async.py) authentication works as expected.

Issue in the SmallRye GraphQL-UI is tracked at https://github.com/smallrye/smallrye-graphql/issues/2255

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.