Skip to content

Commit 92e302d

Browse files
committed
implement with own schema
1 parent 1734a50 commit 92e302d

File tree

2 files changed

+49
-51
lines changed

2 files changed

+49
-51
lines changed

src/index.js

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,60 @@ 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 {
18-
// schema,
19-
resolvers,
20-
} from './schema';
17+
import { schema, resolvers } from './schema';
2118

2219
import registerServiceWorker from './registerServiceWorker';
2320

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();
21+
// async function render() {
22+
const cache = new InMemoryCache();
23+
24+
// const GITHUB_BASE_URL = 'https://api.github.com/graphql';
25+
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+
// });
34+
35+
// const schema = await introspectSchema(httpLink);
36+
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();
6260

6361
registerServiceWorker();

src/schema.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export const schema = `
33
organization(login: String!): Organization!
44
}
55
6+
interface Starrable {
7+
id: ID!
8+
viewerHasStarred: Boolean!
9+
}
10+
611
type Organization {
712
name: String!
813
url: String!
@@ -18,7 +23,7 @@ export const schema = `
1823
}
1924
2025
type Repository implements Starrable {
21-
id: String!
26+
id: ID!
2227
name: String!
2328
url: String!
2429
viewerHasStarred: Boolean!
@@ -35,11 +40,6 @@ export const schema = `
3540
type AddStarPayload {
3641
starrable: Starrable!
3742
}
38-
39-
type Starrable {
40-
id: ID!
41-
viewerHasStarred: Boolean!
42-
}
4343
`;
4444

4545
export const resolvers = {

0 commit comments

Comments
 (0)