Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cannot use context headers in GraphQL's subscription function. #815

Closed
kim-mini6 opened this issue Feb 17, 2021 · 9 comments · Fixed by #1016
Closed

cannot use context headers in GraphQL's subscription function. #815

kim-mini6 opened this issue Feb 17, 2021 · 9 comments · Fixed by #1016
Assignees
Labels
🐛 bug Something isn't working dart client Issue relates mainly to the standalone dart client
Milestone

Comments

@kim-mini6
Copy link

Is my code.

final WebSocketLink websocketLink = WebSocketLink(
      'test',
      config: SocketClientConfig(
        initialPayload: {
          "headers": {},
        },
      ),
    );

I don't want to use headers in the code above.

Please look at the code below.

SubscriptionOptions(
            operationName: 'messages',
            document: gql(r'''
              subscription messages($where: messages_bool_exp!) {
                messages(where: $where) {
                  ...messagesFragment
                }
              }
                ''' +
                fragments +
                '''
            '''),
            variables: {
              "where": {
                "id": {
                  "_eq": "test",
                },
              },
            },
            fetchPolicy: FetchPolicy.cacheAndNetwork,
            context: Context().withEntry(
              HttpLinkHeaders(
                headers: headers(idToken),
              ),
            ),
          );

Here I want to add a header to the context.

For general queries other than subscriptions, the context header works fine.

error message : cannot start as connection_init failed with : Missing Authorization header in JWT authentication mode.

@micimize
Copy link
Collaborator

This is a known issue – you can use this workaround in the meantime

@kim-mini6
Copy link
Author

Thanks for the answer but it's not the workaround I want

@kateile
Copy link

kateile commented Apr 7, 2021

@micimize the workaround works amazing. will headers be added in the next WSLink?

@micimize
Copy link
Collaborator

micimize commented Apr 7, 2021

@kateile after seeing the null safety v5 release to a stable version (along with its dependencies in the gql project), I do not plan on making any more feature or improvement contributions. Aside from the reasons I mentioned in #763, I have stopped using GraphQL in my own project and unfortunately it no longer makes sense for me to continue contributing here.

I haven't seen @HofmannZ or @eusdima around here in a long time so unless someone else steps in as active maintainer this project can be considered in low maintenance mode. Some people have expressed some interest in contributing in #762 but we'll see. Hopefully when I get around to the walkthrough vid it will help users PR fixes to their own problems.

@kateile
Copy link

kateile commented Dec 31, 2021

@vincenzopalazzo can we solve this too in the coming updates?

@vincenzopalazzo
Copy link
Collaborator

Hi @kateile, these are some things that I can put in the queue, but do you test it with the last version of the package?

If yes, could you please propose a reproducible example?

@vincenzopalazzo vincenzopalazzo added 🐛 bug Something isn't working ⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug 👵 outdated Outdated and will be closed soon unless reproduced on the latest beta dart client Issue relates mainly to the standalone dart client labels Dec 31, 2021
@vincenzopalazzo vincenzopalazzo self-assigned this Dec 31, 2021
@micimize
Copy link
Collaborator

@vincenzopalazzo this is more an API tweak for how to provide headers to the WebSocketLink. In essence, it would be adding a parameter to the default connect parameter, rather than requiring overriding it, so that a user could do the following:

SocketClientConfig(
  ...
- connect: (url, protocols) =>
-   IOWebSocketChannel.connect(url, protocols: protocols, headers: myCustomHeaders)
+ headers: myCustomHeaders
)

@vincenzopalazzo vincenzopalazzo added this to the v5.0.1 milestone Jan 7, 2022
@vincenzopalazzo vincenzopalazzo removed 👵 outdated Outdated and will be closed soon unless reproduced on the latest beta ⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug labels Jan 11, 2022
@vincenzopalazzo
Copy link
Collaborator

I implemented the feature suggested by @micimize (BTW thanks), in the following PR #1016

I'm releasing the new beta version (beta.6), so we will be happy to receive feedback from the users

@kim-mini6
Copy link
Author

Thank you very much. I will always support you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
🐛 bug Something isn't working dart client Issue relates mainly to the standalone dart client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants