Comments (19)
@jbaxleyiii Since credentials
is configurable on apollo-link-http
, but it is not available on apollo-link-batch-http
.
from apollo-link.
any news on credentials
being available for apollo-link-batch-http
?
from apollo-link.
Would be great to have it on apollo-link-batch-http
, we had to disable batching in production and are seeing a huge increase in dyno usage.
from apollo-link.
I think we should allow credentials and headers to the constructor for the http-link https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http#options.
I'll assign and do this!
from apollo-link.
Yep, I'll get something over in a bit
from apollo-link.
Supported via #144!
from apollo-link.
Hmm, this is definitely one thing that was easier in the previous network interface implementation. I think it should probably be possible to do everything with just HttpLink
IMO, but curious what @jbaxleyiii thinks.
from apollo-link.
Also, @jaydenseric what do you think?
from apollo-link.
Just asked James, we like the first example:
new HttpLink({
uri: 'https://www.example.com/graphql',
credentials: 'include',
headers: {
'X-Example-Header': config.VERSION
}
})
I think that would include modifications to apollo fetch as well, right?
from apollo-link.
Cool
I think that would include modifications to apollo fetch as well, right?
Correct, they'd pass through from HttpLink
/BatchHttpLink
to apollo fetch and presumably be merged into the options object here.
from apollo-link.
@tgriesser that would be awesome - do you have time to work on a PR for that?
from apollo-link.
Thanks!
from apollo-link.
Also, @jaydenseric what do you think?
I don't fully appreciate the consequences of this proposal as the way all these new packages link together still hasn't clicked for me yet, even though I'm productively using them.
Unless I'm confused, is it a good idea this high up in the API to bake in support for fetch
API options such as credentials: 'include'
when a custom fetch function might use something other than fetch
internally, such as XHR?
As an side note, auth header examples are pretty different looking between apollo-link
and apollo-fetch
:
- https://github.com/apollographql/apollo-link/blob/master/docs/summary.md#authentication
- https://github.com/apollographql/apollo-fetch#middleware
Is apollo-link
really intended to be used directly when building apps anyway?
this is definitely one thing that was easier in the previous network interface implementation.
IMO it has been as easy, or easier (WIP documentation aside) than before to set everything up. A real-world batched client setup with auth headers and uploads for a SSR Next.js app (see example without auth here for context):
import { ApolloClient } from 'react-apollo'
import BatchHttpLink from 'apollo-link-batch-http'
import { createApolloFetchUpload } from 'apollo-fetch-upload'
function createApolloClient({ initialState, getViewerToken }) {
const apolloUploadFetch = createApolloFetchUpload({
uri: `${process.env.API_URI}/graphql`
})
apolloUploadFetch.batchUse(({ options }, next) => {
const viewerToken = getViewerToken()
if (viewerToken) {
if (!options.headers) options.headers = {}
options.headers.authorization = `Bearer ${viewerToken}`
}
next()
})
return new ApolloClient({
ssrMode: !process.browser,
initialState,
networkInterface: new BatchHttpLink({ fetch: apolloUploadFetch })
})
}
For auth related fetch headers I used to have them fixed for SSR and as middleware for the client, in case the viewer situation changes between operations in a group of batched requests. For simplicity I just use middleware for both now since it doesn't seem to really slow SSR.
from apollo-link.
Is apollo-link really intended to be used directly when building apps anyway?
I'd claim that the code sample above qualifies as "using it directly", since you still have to deal with the configuration API.
I think you've got a good point about custom fetch functions that might have different APIs than window.fetch
.
Would it be fair to say that the idea of building this into apollo-fetch
is less controversial? What's our confidence level that having a credentials: include
option on apollo-fetch
would be a good idea?
from apollo-link.
I might not fully understand the challenge here, but perhaps credentials
could be used at the Link level or the fetch level where fetch defined credentials override Link defined credentials. It seems like the design approach has been to provide helpful defaults in a Link in addition to providing convenient ways to set fetch behavior.
Until this lands on an established pattern, I'll be taking this approach which seems independent of any changes made Link-wise.
const fetch = createApolloFetchUpload({
uri: '/graphql'
});
fetch.batchUse(({ options }, next) => {
options.credentials = 'same-origin';
next();
});
I also noticed the docs have been getting updated recently. Does anyone know the current API design direction for this issue?
from apollo-link.
@moimael until there's an API on apollo-link-batch-http
the workaround is using the solution described here: #44 (comment)
from apollo-link.
@tgriesser, @stubailo, any news on solving this?
from apollo-link.
Can you open a new issue specifically for the batch link?
from apollo-link.
from apollo-link.
Related Issues (20)
- onError giving me terminating link and hence, `from` throws LinkError
- Type error after upgrading to graphql@15 HOT 7
- '__spreadArrays' was not found
- Axios instance as fetch implementation HOT 1
- How to use apollo-link-batch-http with Angular?
- Multiline package description on npm
- TypeScript error in Header authentication tutorial HOT 1
- apollo-link-ws loads backend modules when using it in the browser HOT 1
- Cannot override `useGETForQueries` to use POST on one specific query
- Request has invalid content type header when using XMLHttpRequest polyfill HOT 1
- How to use 2 terminating Links?
- OnError Apollo i will like to show/display the error HOT 3
- Client - Only absolute URLs are supported
- graphQLErrors returns an empty array for mutations onError
- Integrating websocket link results in constat logging in console HOT 2
- Apollo v3 Beta not working with RetryLink and onError HOT 2
- Pagination Apollo v3
- Update Dependencies (Renovate Bot)
- setContext in the errorLink is not updating the global header token
- operation context gets lost?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-link.