f / graphql.js

A Simple and Isomorphic GraphQL Client for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON parse error when using OAuth token

rajinder-yadav opened this issue · comments

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' }

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