File tree Expand file tree Collapse file tree 5 files changed +71
-31
lines changed Expand file tree Collapse file tree 5 files changed +71
-31
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ extensions:
6
6
headers :
7
7
Authorization : " Bearer ${env:GITHUB_TOKEN}"
8
8
codegen :
9
- generator : binding-http
10
- source-schema : schema-with-import-statement .graphql
9
+ generator : binding
10
+ target : src/generated-binding .graphql
Original file line number Diff line number Diff line change 14
14
},
15
15
"dependencies" : {
16
16
"apollo-link" : " 1.2.1" ,
17
- "apollo-link-http" : " 1.3 .3" ,
17
+ "apollo-link-http" : " 1.5 .3" ,
18
18
"cross-fetch" : " 2.1.0" ,
19
19
"graphql" : " 0.13.2" ,
20
20
"graphql-binding" : " 1.2.5" ,
21
- "graphql-tools" : " 2.21.0 "
21
+ "graphql-tools" : " 2.23.1 "
22
22
},
23
23
"devDependencies" : {
24
24
"@types/graphql" : " 0.13.0" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 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'
5
4
5
+ export class GitHubLink extends HttpLink {
6
6
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
+ } )
12
17
}
18
+ }
13
19
14
- // TODO: remoteResolvers
20
+ export class GitHub extends Binding {
21
+ constructor ( token : string ) {
22
+ super ( { link : new GitHubLink ( token ) } )
23
+ }
15
24
}
You can’t perform that action at this time.
0 commit comments