Skip to content

Commit 07d65e9

Browse files
committed
prepared generated stub
1 parent 72e04ae commit 07d65e9

File tree

5 files changed

+71
-31
lines changed

5 files changed

+71
-31
lines changed

.graphqlconfig.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ extensions:
66
headers:
77
Authorization: "Bearer ${env:GITHUB_TOKEN}"
88
codegen:
9-
generator: binding-http
10-
source-schema: schema-with-import-statement.graphql
9+
generator: binding
10+
target: src/generated-binding.graphql

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
},
1515
"dependencies": {
1616
"apollo-link": "1.2.1",
17-
"apollo-link-http": "1.3.3",
17+
"apollo-link-http": "1.5.3",
1818
"cross-fetch": "2.1.0",
1919
"graphql": "0.13.2",
2020
"graphql-binding": "1.2.5",
21-
"graphql-tools": "2.21.0"
21+
"graphql-tools": "2.23.1"
2222
},
2323
"devDependencies": {
2424
"@types/graphql": "0.13.0",

src/GitHubLink.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/generated-binding.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Binding } from 'graphql-binding'
2+
import { ApolloLink } from 'apollo-link'
3+
import { makeRemoteExecutableSchema } from 'graphql-tools'
4+
import { InlineFragmentNode } from 'graphql'
5+
6+
export interface FragmentReplacements {
7+
[typeName: string]: {
8+
[fieldName: string]: InlineFragmentNode
9+
}
10+
}
11+
12+
export interface BindingOptions {
13+
fragmentReplacements?: FragmentReplacements
14+
link: ApolloLink
15+
before?: () => void
16+
handler?: any
17+
subscriptionHandler?: any
18+
}
19+
20+
const typeDefs = `
21+
// GENERATED
22+
`
23+
24+
export default class GeneratedBinding extends Binding {
25+
constructor({
26+
link,
27+
fragmentReplacements,
28+
before,
29+
handler,
30+
subscriptionHandler,
31+
}: BindingOptions) {
32+
const schema = makeRemoteExecutableSchema({
33+
schema: typeDefs,
34+
link,
35+
})
36+
37+
super({
38+
schema,
39+
fragmentReplacements,
40+
before,
41+
handler,
42+
subscriptionHandler,
43+
})
44+
}
45+
46+
// GENERATE `query, mutation, subscription`
47+
// see: https://github.com/graphql-binding/graphql-static-binding/blob/master/src/generators/prisma-ts.ts
48+
}

src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
import { Binding } from 'graphql-binding/dist'
2-
import GitHubLink from './GitHubLink'
3-
4-
export class GitHub extends Binding {
1+
import Binding from './generated-binding'
2+
import { HttpLink } from 'apollo-link-http'
3+
import * as fetch from 'cross-fetch'
54

5+
export class GitHubLink extends HttpLink {
66
constructor(token: string) {
7-
8-
// TODO: come up with a way how to import generated code
9-
10-
const link = new GitHubLink(token)
11-
7+
if (!token) {
8+
throw new Error(
9+
'No Github token provided. Create one here: https://github.com/settings/tokens (Guide: https://developer.github.com/v4/guides/forming-calls/#authenticating-with-graphql)',
10+
)
11+
}
12+
super({
13+
uri: 'https://api.github.com/graphql',
14+
headers: { Authorization: `Bearer ${token}` },
15+
fetch,
16+
})
1217
}
18+
}
1319

14-
// TODO: remoteResolvers
20+
export class GitHub extends Binding {
21+
constructor(token: string) {
22+
super({ link: new GitHubLink(token) })
23+
}
1524
}

0 commit comments

Comments
 (0)