question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use setContext with Apollo Client 3.0

See original GitHub issue

Intended outcome: using Bearer Authentication, thus having looked up in the docs how to do it: https://www.apollographql.com/docs/react/v3.0-beta/networking/authentication/#header

Actual outcome: https://www.apollographql.com/docs/react/v3.0-beta/networking/authentication/#header In the code example, setContext is used, but it isn’t shown where it is imported from. I can find references in the web, that one should import it from apollo-link-context, but I am not sure whether this is still the way to go with v3.0. Anyways, I think in the docs it should be methioned where to import it from 😊

How to reproduce the issue: Try to follow the docs

Versions System: OS: macOS 10.15.3 Binaries: Node: 10.19.0 - ~/.nvm/versions/node/v10.19.0/bin/node Yarn: 1.22.4 - ~/.nvm/versions/node/v10.19.0/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v10.19.0/bin/npm Browsers: Chrome: 80.0.3987.149 Firefox: 74.0 Safari: 13.0.5 npmPackages: @apollo/client: ^3.0.0-beta.41 => 3.0.0-beta.41 @apollo/link-ws: ^2.0.0-beta.3 => 2.0.0-beta.3

Thank you so much in advance for your time!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
Jiertcommented, Jul 14, 2020

@hannojg use this:

import { setContext } from '@apollo/client/link/context';

https://www.apollographql.com/docs/react/networking/authentication/#header

5reactions
dodascommented, Mar 31, 2020

Most of the apollo-link-* packages are now under @apollo/link-* namespace.

import { setContext } from "@apollo/link-context";

I agree that this is poorly documented so far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context Link - Apollo GraphQL Docs
The setContext function accepts a function that returns either an object or a promise, which then returns an object to set the new...
Read more >
Unable to set Auth Headers using Apollo Client 3 and ...
Doesn't work for me it seems like apollo just complelty ignores the authlink and doesn't even run it. When I put console.logs in...
Read more >
Set Context with Apollo Client - YouTube
Quite often there will be times you'll want to update your Apollo Client based on the behaviour of users in your app, or...
Read more >
How to use the apollo-link-context.setContext function ... - Snyk
To help you get started, we've selected a few apollo-link-context.setContext examples, based on popular ways it is used in public projects.
Read more >
Using with Apollo Client — absinthe v1.7.0 - HexDocs
The setContext helper allows you to do this, and also demonstrates how links in Apollo can be chained. import ApolloClient from "apollo-client"; import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found