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

Allow passing more options to fetch #6

Closed
jovinbm opened this issue Jun 14, 2017 · 4 comments
Closed

Allow passing more options to fetch #6

jovinbm opened this issue Jun 14, 2017 · 4 comments

Comments

@jovinbm
Copy link

jovinbm commented Jun 14, 2017

First, thank you for the awesome work!

Currently the library seems to be only pass the headers option to fetch whilst fetch takes many more options like

fetch('https://example.com', {
  credentials: 'include'  
})

I'm not that familiar with typescript to make a quick pull request without messing things up, but perhaps keeping all the passed in options at https://github.com/graphcool/graphql-request/blob/master/src/index.ts#L18 and something like

const response = await fetch(this.url, Object.assign({}, this.options, {
      method: 'POST',
      headers: Object.assign({'Content-Type': 'application/json'}, this.options.headers),
      body,
    }))

at https://github.com/graphcool/graphql-request/blob/master/src/index.ts#L30.

@schickling
Copy link
Contributor

The idea looks reasonable, however I wonder how to deal with the body property in particular.

@IvanGoncharov @RomanGotsiy any feedback here?

@RomanHotsiy
Copy link
Contributor

@schickling this sounds reasonable.
Regarding body property, I would just ignore it (especially since options can be used to init client instance and body doesn't make sense here). I would also not include body in typescript typing for Options so typescript users will be notified that body property is not expected.

Something like this:

const response = await fetch(this.url, {
  method: 'POST',
  ...this.options, // to allow overwrite method but merge headers and ignore body
  headers: Object.assign({'Content-Type': 'application/json'}, this.options.headers),
  body,
})

@schickling
Copy link
Contributor

Sounds good! Does somebody want to create a PR + some tests for this?

@RomanHotsiy
Copy link
Contributor

I can make a PR on weekends if nobody creates it earlier

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

3 participants