@@ -40,10 +40,6 @@ const { sign } = require('jsonwebtoken');
40
40
const schemaCache = new SchemaCache()
41
41
42
42
class BaseBinding {
43
- remoteSchema
44
- fragmentReplacements
45
- graphqlClient
46
-
47
43
constructor({
48
44
typeDefs,
49
45
endpoint,
@@ -101,27 +97,32 @@ ${schema}\``
101
97
102
98
103
99
function renderMainMethod ( queryType : GraphQLObjectType , mutationType ?: GraphQLObjectType | null , subscriptionType ?: GraphQLObjectType | null ) {
104
- return `export class Binding extends BaseBinding {
100
+ return `module.exports.Binding = class Binding extends BaseBinding {
105
101
106
102
constructor({ endpoint, secret, fragmentReplacements}) {
107
103
super({ typeDefs, endpoint, secret, fragmentReplacements});
108
- }
109
-
110
- query = {
111
- ${ renderMainMethodFields ( 'query' , queryType . getFields ( ) ) }
112
- }${ mutationType ? `
113
104
114
- mutation = {
105
+ var self = this
106
+ this.query = {
107
+ ${ renderMainMethodFields ( 'query' , queryType . getFields ( ) ) }
108
+ }${ mutationType ? `
109
+
110
+ this.mutation = {
115
111
${ renderMainMethodFields ( 'mutation' , mutationType . getFields ( ) ) }
116
- }` : '' }
112
+ }` : '' }
113
+ }
114
+
115
+ delegate(operation, field, args, info) {
116
+ return super.delegate(operation, field, args, info)
117
+ }
117
118
}`
118
119
}
119
120
120
121
function renderMainMethodFields ( operation : string , fields : GraphQLFieldMap < any , any > ) : string {
121
122
return Object . keys ( fields ) . map ( f => {
122
123
const field = fields [ f ]
123
- return ` ${ field . name } (args, info) {
124
- return super .delegate('${ operation } ', '${ field . name } ', args, info)
125
- }`
124
+ return ` ${ field . name } (args, info) {
125
+ return self .delegate('${ operation } ', '${ field . name } ', args, info)
126
+ }`
126
127
} ) . join ( ',\n' )
127
128
}
0 commit comments