|
1 | 1 | import { Binding } from 'graphql-binding/dist' |
2 | | -import { IResolvers } from 'graphql-tools/dist/Interfaces' |
3 | | -import { makeRemoteExecutableSchema } from 'graphql-tools' |
4 | | -import { GraphQLSchema, GraphQLUnionType, GraphQLInterfaceType, buildSchema } from 'graphql' |
5 | | -import * as fs from 'fs' |
6 | | -import * as path from 'path' |
7 | 2 | import GitHubLink from './GitHubLink' |
8 | 3 |
|
9 | 4 | export class GitHub extends Binding { |
| 5 | + |
10 | 6 | constructor(token: string) { |
11 | | - const typeDefs = fs.readFileSync(path.join(__dirname, '..', 'schema', 'github.graphql'), { |
12 | | - encoding: 'utf8' |
13 | | - }) |
14 | 7 |
|
15 | | - const link = new GitHubLink(token) |
| 8 | + // TODO: come up with a way how to import generated code |
16 | 9 |
|
17 | | - const schema = makeRemoteExecutableSchema({ |
18 | | - schema: typeDefs, |
19 | | - link |
20 | | - }) |
| 10 | + const link = new GitHubLink(token) |
21 | 11 |
|
22 | | - super({ schema, fragmentReplacements: {} }) |
23 | 12 | } |
24 | 13 |
|
25 | | - remoteResolvers(filterSchema?: GraphQLSchema | string): IResolvers { |
26 | | - const typeMap = this.schema.getTypeMap() |
27 | | - |
28 | | - if (filterSchema && typeof filterSchema === 'string') { |
29 | | - filterSchema = buildSchema(filterSchema) |
30 | | - } |
31 | | - const filterTypeMap = filterSchema instanceof GraphQLSchema ? filterSchema.getTypeMap() : typeMap |
32 | | - const filterType = typeName => typeName in filterTypeMap |
33 | | - |
34 | | - const resolvers = {} |
35 | | - Object.keys(typeMap) |
36 | | - .filter(filterType) |
37 | | - .forEach(typeName => { |
38 | | - const type = typeMap[typeName] |
39 | | - if (type instanceof GraphQLUnionType || type instanceof GraphQLInterfaceType) { |
40 | | - resolvers[typeName] = { |
41 | | - __resolveType: type.resolveType |
42 | | - } |
43 | | - } |
44 | | - }) |
45 | | - |
46 | | - return resolvers |
47 | | - } |
| 14 | + // TODO: remoteResolvers |
48 | 15 | } |
0 commit comments