f / graphql.js

A Simple and Isomorphic GraphQL Client for JavaScript
MIT License
2.26k stars 89 forks source link

JSON parse error when using OAuth token #35

Open rajinder-yadav opened 5 years ago

rajinder-yadav commented 5 years ago

I've got this to work using Postman, however the following code generates a JSON parse error?

Code

const graphql = require('graphql.js');
const graph = graphql('https://api.github.com/graphql', {
  method: "POST",
  headers: {
    "User-Agent": "node",
    "Authorization": "Bearer <github-token>"
  }
});

const query = graph(`query { viewer { login name } }`);

query().then(
  res => console.log(JSON.stringify(res)),
  err => console.error(err)
);

Error

{ message: 'Problems parsing JSON',
  documentation_url: 'https://developer.github.com/v4' }
rajinder-yadav commented 5 years ago

You can generate your token here: https://github.com/settings/tokens