@@ -2,43 +2,62 @@ import React from 'react';
22import ReactDOM from 'react-dom' ;
33import { ApolloProvider } from 'react-apollo' ;
44import { ApolloClient } from 'apollo-client' ;
5- // import { HttpLink } from 'apollo-link-http';
5+ import { HttpLink } from 'apollo-link-http' ;
66import { InMemoryCache } from 'apollo-cache-inmemory' ;
77
88import { SchemaLink } from 'apollo-link-schema' ;
9- import { makeExecutableSchema } from 'graphql-tools' ;
9+ import {
10+ makeExecutableSchema ,
11+ introspectSchema ,
12+ } from 'graphql-tools' ;
13+
14+ import { printSchema } from 'graphql/utilities/schemaPrinter' ;
1015
1116import App from './App' ;
12- import { typeDefs , resolvers } from './schema' ;
17+ import {
18+ // schema,
19+ resolvers ,
20+ } from './schema' ;
1321
1422import registerServiceWorker from './registerServiceWorker' ;
1523
16- const cache = new InMemoryCache ( ) ;
17-
18- // const GITHUB_BASE_URL = 'https://api.github.com/graphql';
19-
20- // const httpLink = new HttpLink({
21- // uri: GITHUB_BASE_URL,
22- // headers: {
23- // authorization: `Bearer ${
24- // process.env.REACT_APP_GITHUB_PERSONAL_ACCESS_TOKEN
25- // }`,
26- // },
27- // });
28-
29- const schema = makeExecutableSchema ( { typeDefs, resolvers } ) ;
30-
31- const client = new ApolloClient ( {
32- // link: httpLink,
33- link : new SchemaLink ( { schema } ) ,
34- cache,
35- } ) ;
36-
37- ReactDOM . render (
38- < ApolloProvider client = { client } >
39- < App />
40- </ ApolloProvider > ,
41- document . getElementById ( 'root' ) ,
42- ) ;
24+ async function render ( ) {
25+ const cache = new InMemoryCache ( ) ;
26+
27+ const GITHUB_BASE_URL = 'https://api.github.com/graphql' ;
28+
29+ const httpLink = new HttpLink ( {
30+ uri : GITHUB_BASE_URL ,
31+ headers : {
32+ authorization : `Bearer ${
33+ process . env . REACT_APP_GITHUB_PERSONAL_ACCESS_TOKEN
34+ } `,
35+ } ,
36+ } ) ;
37+
38+ const schema = await introspectSchema ( httpLink ) ;
39+
40+ const executableSchema = makeExecutableSchema ( {
41+ typeDefs : printSchema ( schema ) ,
42+ resolvers,
43+ resolverValidationOptions : {
44+ requireResolversForResolveType : false ,
45+ } ,
46+ } ) ;
47+
48+ const client = new ApolloClient ( {
49+ link : new SchemaLink ( { schema : executableSchema } ) ,
50+ cache,
51+ } ) ;
52+
53+ ReactDOM . render (
54+ < ApolloProvider client = { client } >
55+ < App />
56+ </ ApolloProvider > ,
57+ document . getElementById ( 'root' ) ,
58+ ) ;
59+ }
60+
61+ render ( ) ;
4362
4463registerServiceWorker ( ) ;
0 commit comments