Skip to content

Passing options for fetch - #105

Merged
Muthurathinam (muthurathinam) merged 5 commits into
devfrom
Passing-Options-For-Fetch
Sep 21, 2018
Merged

Muthurathinam (muthurathinam) merged 5 commits into
devfrom
Passing-Options-For-Fetch

Conversation

@muthurathinam

Copy link
Copy Markdown
Contributor

Fetch API options

There are node environment specific needs such as passing agent (http(s).Agent instance, allows custom proxy etc.), timeout for request, number of follows for a continuous redirect etc., and these options needs to be passed to fetch call through its RequestInit param (second param).

We have enabled two ways to pass these options for a request.

  1. Passing options while initializing the GraphClient. Options can be any Node specific or Fetch standard
    Note: This configuration applies to all the requests that are made through GraphClient
const client = MicrosoftGraph.init({
    defaultVersion: 'v1.0',
    debugLogging: true,
    authProvider: (done) => {
        done(null, secrets.accessToken);
    },
    fetchOptions: {
        timeout: 5,
        follow: 20
    }
});
  1. Pass in for every request with .option and .options functionality.
    Note: This applies to the particular request
client
    .api('/me')
    .select("displayName")
    .option("redirect", "allow")
    .options({
        timeout: "500"
    })
    .get((err, res) => {
        if (err) {
            console.log(err)
            return;
        }
        console.log(res.displayName);
    });

Bugs Fixed:

  1. Unable to use the library through a proxy #97
  2. Timeout property of superagent library should be exposed #39

Comment thread lib/src/common.d.ts
* A package version
* @NOTE: This should be kept up to date with the version used in package.json.
* If you are changing this please ensure you are also changing it in package.json.
*/

@MIchaelMainer Michael Mainer (MIchaelMainer) Sep 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: I'd like for scenarios like this to be checked with either a pre-commit hook script or via CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a very good option. will do that.!

Comment thread src/common.ts
* @extends
* support oData params with and without $ prefix
*/
oDataQueryNames = oDataQueryNames.concat(oDataQueryNames.map((s) => "$" + s));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this PR but we should include search and format as values in oDataQueryNames

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is something we have in our plate. will make a different PR for that.

Comment thread README.md Outdated

````

## .option() and .options()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a heading 3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

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

Successfully merging this pull request may close these issues.

5 participants