graphql-static-binding
Advanced tools
Comparing version
@@ -8,6 +8,6 @@ "use strict"; | ||
function renderHeader(schema) { | ||
return "const { FragmentReplacements } = require('graphcool-binding/dist/src/extractFragmentReplacements');\nconst { GraphcoolLink } = require('graphcool-binding/dist/src/GraphcoolLink');\nconst { buildFragmentInfo, buildTypeLevelInfo } = require('graphcool-binding/dist/src/prepareInfo');\nconst { GraphQLResolveInfo, GraphQLSchema } = require('graphql');\nconst { GraphQLClient } = require('graphql-request');\nconst { SchemaCache } = require('graphql-schema-cache');\nconst { delegateToSchema } = require('graphql-tools');\nconst { sign } = require('jsonwebtoken');\n\n// -------------------\n// This should be in graphcool-binding\nconst schemaCache = new SchemaCache()\n\nclass BaseBinding {\n remoteSchema\n fragmentReplacements\n graphqlClient\n\n constructor({\n typeDefs,\n endpoint,\n secret,\n fragmentReplacements}) {\n \n fragmentReplacements = fragmentReplacements || {}\n\n const token = sign({}, secret)\n const link = new GraphcoolLink(endpoint, token)\n\n this.remoteSchema = schemaCache.makeExecutableSchema({\n link,\n typeDefs,\n key: endpoint,\n })\n\n this.fragmentReplacements = fragmentReplacements\n\n this.graphqlClient = new GraphQLClient(endpoint, {\n headers: { Authorization: `Bearer ${token}` },\n })\n }\n\n delegate(operation, prop, args, info) {\n if (!info) {\n info = buildTypeLevelInfo(prop, this.remoteSchema, operation)\n } else if (typeof info === 'string') {\n info = buildFragmentInfo(prop, this.remoteSchema, operation, info)\n }\n\n return delegateToSchema(\n this.remoteSchema,\n this.fragmentReplacements,\n operation,\n prop,\n args || {},\n {},\n info,\n )\n }\n\n async request(\n query,\n variables\n ) {\n return this.graphqlClient.request(query, variables)\n }\n}\n// -------------------\n\nconst typeDefs = `\n" + schema + "`"; | ||
return "const { FragmentReplacements } = require('graphcool-binding/dist/src/extractFragmentReplacements');\nconst { GraphcoolLink } = require('graphcool-binding/dist/src/GraphcoolLink');\nconst { buildFragmentInfo, buildTypeLevelInfo } = require('graphcool-binding/dist/src/prepareInfo');\nconst { GraphQLResolveInfo, GraphQLSchema } = require('graphql');\nconst { GraphQLClient } = require('graphql-request');\nconst { SchemaCache } = require('graphql-schema-cache');\nconst { delegateToSchema } = require('graphql-tools');\nconst { sign } = require('jsonwebtoken');\n\n// -------------------\n// This should be in graphcool-binding\nconst schemaCache = new SchemaCache()\n\nclass BaseBinding {\n constructor({\n typeDefs,\n endpoint,\n secret,\n fragmentReplacements}) {\n \n fragmentReplacements = fragmentReplacements || {}\n\n const token = sign({}, secret)\n const link = new GraphcoolLink(endpoint, token)\n\n this.remoteSchema = schemaCache.makeExecutableSchema({\n link,\n typeDefs,\n key: endpoint,\n })\n\n this.fragmentReplacements = fragmentReplacements\n\n this.graphqlClient = new GraphQLClient(endpoint, {\n headers: { Authorization: `Bearer ${token}` },\n })\n }\n\n delegate(operation, prop, args, info) {\n if (!info) {\n info = buildTypeLevelInfo(prop, this.remoteSchema, operation)\n } else if (typeof info === 'string') {\n info = buildFragmentInfo(prop, this.remoteSchema, operation, info)\n }\n\n return delegateToSchema(\n this.remoteSchema,\n this.fragmentReplacements,\n operation,\n prop,\n args || {},\n {},\n info,\n )\n }\n\n async request(\n query,\n variables\n ) {\n return this.graphqlClient.request(query, variables)\n }\n}\n// -------------------\n\nconst typeDefs = `\n" + schema + "`"; | ||
} | ||
function renderMainMethod(queryType, mutationType, subscriptionType) { | ||
return "export class Binding extends BaseBinding {\n \n constructor({ endpoint, secret, fragmentReplacements}) {\n super({ typeDefs, endpoint, secret, fragmentReplacements});\n }\n \n query = {\n" + renderMainMethodFields('query', queryType.getFields()) + "\n }" + (mutationType ? "\n\n mutation = {\n" + renderMainMethodFields('mutation', mutationType.getFields()) + "\n }" : '') + "\n}"; | ||
return "module.exports.Binding = class Binding extends BaseBinding {\n \n constructor({ endpoint, secret, fragmentReplacements}) {\n super({ typeDefs, endpoint, secret, fragmentReplacements});\n\n var self = this\n this.query = {\n" + renderMainMethodFields('query', queryType.getFields()) + "\n }" + (mutationType ? "\n \n this.mutation = {\n" + renderMainMethodFields('mutation', mutationType.getFields()) + "\n }" : '') + "\n }\n \n delegate(operation, field, args, info) {\n return super.delegate(operation, field, args, info)\n }\n}"; | ||
} | ||
@@ -17,5 +17,5 @@ function renderMainMethodFields(operation, fields) { | ||
var field = fields[f]; | ||
return " " + field.name + "(args, info) { \n return super.delegate('" + operation + "', '" + field.name + "', args, info)\n }"; | ||
return " " + field.name + "(args, info) { \n return self.delegate('" + operation + "', '" + field.name + "', args, info)\n }"; | ||
}).join(',\n'); | ||
} | ||
//# sourceMappingURL=javascript.js.map |
{ | ||
"name": "graphql-static-binding", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Generate static binding files for a GraphQL schema", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
36794
0.32%