@@ -40,10 +40,6 @@ const { sign } = require('jsonwebtoken');
4040const schemaCache = new SchemaCache()
4141
4242class BaseBinding {
43- remoteSchema
44- fragmentReplacements
45- graphqlClient
46-
4743 constructor({
4844 typeDefs,
4945 endpoint,
@@ -101,27 +97,32 @@ ${schema}\``
10197
10298
10399function 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 {
105101
106102 constructor({ endpoint, secret, fragmentReplacements}) {
107103 super({ typeDefs, endpoint, secret, fragmentReplacements});
108- }
109-
110- query = {
111- ${ renderMainMethodFields ( 'query' , queryType . getFields ( ) ) }
112- }${ mutationType ? `
113104
114- mutation = {
105+ var self = this
106+ this.query = {
107+ ${ renderMainMethodFields ( 'query' , queryType . getFields ( ) ) }
108+ }${ mutationType ? `
109+
110+ this.mutation = {
115111${ renderMainMethodFields ( 'mutation' , mutationType . getFields ( ) ) }
116- }` : '' }
112+ }` : '' }
113+ }
114+
115+ delegate(operation, field, args, info) {
116+ return super.delegate(operation, field, args, info)
117+ }
117118}`
118119}
119120
120121function renderMainMethodFields ( operation : string , fields : GraphQLFieldMap < any , any > ) : string {
121122 return Object . keys ( fields ) . map ( f => {
122123 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+ }`
126127 } ) . join ( ',\n' )
127128}
0 commit comments