Skip to content

Commit 72e04ae

Browse files
committed
init codegen refactoring
1 parent 457c331 commit 72e04ae

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

.graphqlconfig.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
schemaPath: src/schema.graphql
2+
extensions:
3+
endpoints:
4+
default:
5+
url: https://api.github.com/graphql
6+
headers:
7+
Authorization: "Bearer ${env:GITHUB_TOKEN}"
8+
codegen:
9+
generator: binding-http
10+
source-schema: schema-with-import-statement.graphql

src/index.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
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'
72
import GitHubLink from './GitHubLink'
83

94
export class GitHub extends Binding {
5+
106
constructor(token: string) {
11-
const typeDefs = fs.readFileSync(path.join(__dirname, '..', 'schema', 'github.graphql'), {
12-
encoding: 'utf8'
13-
})
147

15-
const link = new GitHubLink(token)
8+
// TODO: come up with a way how to import generated code
169

17-
const schema = makeRemoteExecutableSchema({
18-
schema: typeDefs,
19-
link
20-
})
10+
const link = new GitHubLink(token)
2111

22-
super({ schema, fragmentReplacements: {} })
2312
}
2413

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
4815
}

schema/github.graphql renamed to src/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# source: https://api.github.com/graphql
2+
# timestamp: Thu Apr 05 2018 23:26:36 GMT+0200 (CEST)
3+
14
"""Autogenerated input type of AcceptTopicSuggestion"""
25
input AcceptTopicSuggestionInput {
36
"""A unique identifier for the client performing the mutation."""

0 commit comments

Comments
 (0)