Skip to content
This repository was archived by the owner on May 10, 2018. It is now read-only.

Commit 1c38e98

Browse files
committed
Fixed javascript generation:
1 parent 64a91c0 commit 1c38e98

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-static-binding",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Generate static binding files for a GraphQL schema",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/generators/javascript.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ const { sign } = require('jsonwebtoken');
4040
const schemaCache = new SchemaCache()
4141
4242
class BaseBinding {
43-
remoteSchema
44-
fragmentReplacements
45-
graphqlClient
46-
4743
constructor({
4844
typeDefs,
4945
endpoint,
@@ -101,27 +97,32 @@ ${schema}\``
10197

10298

10399
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 {
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

120121
function 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

Comments
 (0)