apollographql / apollo-link

:link: Interface for fetching and modifying control flow of GraphQL requests
https://www.apollographql.com/docs/link/
MIT License
1.44k stars 344 forks source link

apollo-link-context docs clarification #572

Open M-Zuber opened 6 years ago

M-Zuber commented 6 years ago

Expected Behavior The apollo-link-context link will send my auth headers to the server.

Actual Behavior Even following the sample in the documentation, the token was not being passed through.

const setAuthorizationLink = setContext((request, previousContext) => ({
  authorization: "1234"
}));

A simple reproduction Just the code above in lieu of whatever else is being used in the app.

The fix is to change the above code to instead be:

const setAuthorizationLink = setContext((request, previousContext) => ({
   headers: {
      authorization: "1234"
    }
}));

Is it better to just change the docs, or consider changing the behavior of the link to add the headers property on it's own? Issue Labels

evans commented 6 years ago

@M-Zuber Thank you for opening the issue! This will be better as a documentation change. Could you make that modification and open a PR?