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

Support setting headers and credentials from context #36

Closed
leethree opened this issue Nov 8, 2017 · 4 comments
Closed

Support setting headers and credentials from context #36

leethree opened this issue Nov 8, 2017 · 4 comments

Comments

@leethree
Copy link

leethree commented Nov 8, 2017

Currently context.headers are being ignored by apollo-upload-client, which is different from the behaviour of apollo-link-http.

See https://github.com/apollographql/apollo-link/blob/9fa5b4dc9cd67577fd118e1f437b2138fe3cd8eb/packages/apollo-link-http/src/httpLink.ts#L114-L119 , headers and credentials from context should merge with fetcherOptions.

@jaydenseric
Copy link
Owner

jaydenseric commented Nov 8, 2017

That's a deliberate API divergence, you can set headers and credentials via context by using fetchOptions (also works in apollo-link-http):

const authLink = new ApolloLink((operation, forward) => {
    const viewerToken = getViewerToken()
    if (viewerToken)
      operation.setContext({
        fetchOptions: {
          headers: {
            authorization: `Bearer ${viewerToken}`
          }
        }
      })
    return forward(operation)
  })

@leethree
Copy link
Author

leethree commented Nov 8, 2017

OK! The workaround looks good to me. Would be great if this behaviour is documented.

Thanks a lot!

@jaydenseric
Copy link
Owner

With apollo-upload-client@6.0.0-beta.2 you should be able to set credentials and headers directly on the link and via context. Please test it out!

@leethree
Copy link
Author

leethree commented Nov 9, 2017

Just upgraded and it's working well. Thanks!

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

No branches or pull requests

2 participants