{"size": 889, "ext": "js", "max_stars_repo_path": "src/js/components/GraphiQL/GraphiQL.js", "max_stars_repo_name": "nicholas-b-carter/react-apollo-starter-kit-1", "max_stars_repo_stars_event_min_datetime": "2016-09-26T21:41:58.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:56:29.000Z", "max_issues_repo_path": "src/js/components/GraphiQL/GraphiQL.js", "max_issues_repo_name": "SDShooter/react-apollo-starter-kit", "max_issues_repo_issues_event_min_datetime": "2016-09-27T17:08:27.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-24T01:37:18.000Z", "max_forks_repo_path": "src/js/components/GraphiQL/GraphiQL.js", "max_forks_repo_name": "SDShooter/react-apollo-starter-kit", "max_forks_repo_forks_event_min_datetime": "2016-09-27T02:47:44.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-18T23:48:03.000Z"}
{"max_stars_count": 77, "max_issues_count": 2, "max_forks_count": 50, "avg_line_length": 22.7948717949, "max_line_length": 78, "alphanum_fraction": 0.6254218223}
import React from 'react';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
import config from './../../../config';
import Header from './../App/Header';
import LoggedInHeader from './../Home/Header';

function graphQLFetcher(graphQLParams) {
  return fetch(config.scapholdUrl, {
    method: 'post',
    headers: {
      'Content-Type': 'application/json',
      Authorization: localStorage.token ? `Bearer ${localStorage.token}` : '',
    },
    body: JSON.stringify(graphQLParams),
  }).then(response => response.json());
}

class GraphiQLModule extends React.Component {
  render() {
    let header;
    if (!localStorage.token) {
      header = <Header />;
    }
    else {
      header = <LoggedInHeader />;
    }

    return (
      <span>
        {header}
        <GraphiQL fetcher={graphQLFetcher} />
      </span>
    )
  }
}

export default GraphiQLModule;
