GithubHelp home page GithubHelp logo

Comments (19)

shendepu avatar shendepu commented on May 3, 2024 22

@jbaxleyiii Since credentials is configurable on apollo-link-http, but it is not available on apollo-link-batch-http.

from apollo-link.

goldo avatar goldo commented on May 3, 2024 15

any news on credentials being available for apollo-link-batch-http ?

from apollo-link.

moimael avatar moimael commented on May 3, 2024 10

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.

jbaxleyiii avatar jbaxleyiii commented on May 3, 2024 2

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.

tgriesser avatar tgriesser commented on May 3, 2024 1

Yep, I'll get something over in a bit

from apollo-link.

jbaxleyiii avatar jbaxleyiii commented on May 3, 2024 1

Supported via #144!

from apollo-link.

stubailo avatar stubailo commented on May 3, 2024

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.

stubailo avatar stubailo commented on May 3, 2024

Also, @jaydenseric what do you think?

from apollo-link.

stubailo avatar stubailo commented on May 3, 2024

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.

tgriesser avatar tgriesser commented on May 3, 2024

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.

stubailo avatar stubailo commented on May 3, 2024

@tgriesser that would be awesome - do you have time to work on a PR for that?

from apollo-link.

stubailo avatar stubailo commented on May 3, 2024

Thanks!

from apollo-link.

jaydenseric avatar jaydenseric commented on May 3, 2024

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:

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.

stubailo avatar stubailo commented on May 3, 2024

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.

AdamYee avatar AdamYee commented on May 3, 2024

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.

rtymchyk avatar rtymchyk commented on May 3, 2024

@moimael until there's an API on apollo-link-batch-http the workaround is using the solution described here: #44 (comment)

from apollo-link.

KROT47 avatar KROT47 commented on May 3, 2024

@tgriesser, @stubailo, any news on solving this?

from apollo-link.

stubailo avatar stubailo commented on May 3, 2024

Can you open a new issue specifically for the batch link?

from apollo-link.

KROT47 avatar KROT47 commented on May 3, 2024

@stubailo done. See #343

from apollo-link.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.