Skip to content

Commit 72e9845

Browse files
committed
implement with their schema (introspection)
1 parent 92e302d commit 72e9845

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

src/index.js

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,63 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { ApolloProvider } from 'react-apollo';
44
import { ApolloClient } from 'apollo-client';
5-
// import { HttpLink } from 'apollo-link-http';
5+
import { HttpLink } from 'apollo-link-http';
66
import { InMemoryCache } from 'apollo-cache-inmemory';
77

88
import { SchemaLink } from 'apollo-link-schema';
99
import {
1010
makeExecutableSchema,
11-
// introspectSchema,
11+
introspectSchema,
1212
} from 'graphql-tools';
1313

14-
// import { printSchema } from 'graphql/utilities/schemaPrinter';
14+
import { printSchema } from 'graphql/utilities/schemaPrinter';
1515

1616
import App from './App';
17-
import { schema, resolvers } from './schema';
17+
import {
18+
// schema,
19+
resolvers,
20+
} from './schema';
1821

1922
import registerServiceWorker from './registerServiceWorker';
2023

21-
// async function render() {
22-
const cache = new InMemoryCache();
24+
async function render() {
25+
const cache = new InMemoryCache();
2326

24-
// const GITHUB_BASE_URL = 'https://api.github.com/graphql';
27+
const GITHUB_BASE_URL = 'https://api.github.com/graphql';
2528

26-
// const httpLink = new HttpLink({
27-
// uri: GITHUB_BASE_URL,
28-
// headers: {
29-
// authorization: `Bearer ${
30-
// process.env.REACT_APP_GITHUB_PERSONAL_ACCESS_TOKEN
31-
// }`,
32-
// },
33-
// });
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+
});
3437

35-
// const schema = await introspectSchema(httpLink);
38+
const schema = await introspectSchema(httpLink);
3639

37-
const executableSchema = makeExecutableSchema({
38-
// typeDefs: printSchema(schema),
39-
typeDefs: schema,
40-
resolvers,
41-
// resolverValidationOptions: {
42-
// requireResolversForResolveType: false,
43-
// },
44-
});
45-
46-
const client = new ApolloClient({
47-
link: new SchemaLink({ schema: executableSchema }),
48-
cache,
49-
});
50-
51-
ReactDOM.render(
52-
<ApolloProvider client={client}>
53-
<App />
54-
</ApolloProvider>,
55-
document.getElementById('root'),
56-
);
57-
// }
58-
59-
// render();
40+
const executableSchema = makeExecutableSchema({
41+
typeDefs: printSchema(schema),
42+
// typeDefs: schema,
43+
resolvers,
44+
resolverValidationOptions: {
45+
requireResolversForResolveType: false,
46+
},
47+
});
48+
49+
const client = new ApolloClient({
50+
link: new SchemaLink({ schema: executableSchema }),
51+
cache,
52+
});
53+
54+
ReactDOM.render(
55+
<ApolloProvider client={client}>
56+
<App />
57+
</ApolloProvider>,
58+
document.getElementById('root'),
59+
);
60+
}
61+
62+
render();
6063

6164
registerServiceWorker();

0 commit comments

Comments
 (0)