graphql-static-binding
Advanced tools
Comparing version
@@ -5,13 +5,16 @@ "use strict"; | ||
Main: renderMainMethod, | ||
Header: function () { return ''; }, | ||
Header: renderHeader, | ||
}; | ||
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 + "`"; | ||
} | ||
function renderMainMethod(queryType, mutationType, subscriptionType) { | ||
return "exports.binding = {\n query: {\n" + renderMainMethodFields(queryType.getFields()) + "\n }" + (mutationType ? ",\n mutation: {\n" + renderMainMethodFields(mutationType.getFields()) + "\n }" : '') + (subscriptionType ? ",\n subscription: {\n" + renderMainMethodFields(subscriptionType.getFields()) + "\n }" : '') + "\n}"; | ||
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}"; | ||
} | ||
function renderMainMethodFields(fields) { | ||
function renderMainMethodFields(operation, fields) { | ||
return Object.keys(fields).map(function (f) { | ||
var field = fields[f]; | ||
return " " + field.name + "(args, info) { \n return /* TODO: Get actual implementation here from graphql-binding */\n }"; | ||
return " " + field.name + "(args, info) { \n return super.delegate('" + operation + "', '" + field.name + "', args, info)\n }"; | ||
}).join(',\n'); | ||
} | ||
//# sourceMappingURL=javascript.js.map |
{ | ||
"name": "graphql-static-binding", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
36675
6.38%17
6.25%217
4.33%0
-100%3
Infinity%