UNPKG

4.63 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
16 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
17 return cooked;
18};
19Object.defineProperty(exports, "__esModule", { value: true });
20var graphql_binding_1 = require("graphql-binding");
21var graphql_1 = require("graphql");
22var utils_1 = require("./utils");
23var PrismaFlowGenerator = /** @class */ (function (_super) {
24 __extends(PrismaFlowGenerator, _super);
25 function PrismaFlowGenerator(options) {
26 return _super.call(this, options) || this;
27 }
28 PrismaFlowGenerator.prototype.render = function () {
29 return this.compile(templateObject_1 || (templateObject_1 = __makeTemplateObject(["/**\n * @flow\n */\n", "\n\nexport interface Query ", "\n\nexport interface Mutation ", "\n\nexport interface Subscription ", "\n\nexport interface Exists ", "\n\ninterface Prisma {\n query: Query;\n mutation: Mutation;\n subscription: Subscription;\n exists: Exists;\n request(query: string, variables?: {[key: string]: any}): Promise<any>;\n delegate(operation: 'query' | 'mutation', fieldName: string, args: {\n [key: string]: any;\n}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<any>;\ndelegateSubscription(fieldName: string, args?: {\n [key: string]: any;\n}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<AsyncIterator<any>>;\ngetAbstractResolvers(filterSchema?: GraphQLSchema | string): IResolvers;\n}\n\nexport interface BindingConstructor<T> {\n new(options: BPOType): T\n}\n/**\n * Type Defs\n*/\n\n", "\n\n", "\n\n/**\n * Types\n*/\n\n", ""], ["\\\n/**\n * @flow\n */\n", "\n\nexport interface Query ", "\n\nexport interface Mutation ", "\n\nexport interface Subscription ", "\n\nexport interface Exists ", "\n\ninterface Prisma {\n query: Query;\n mutation: Mutation;\n subscription: Subscription;\n exists: Exists;\n request(query: string, variables?: {[key: string]: any}): Promise<any>;\n delegate(operation: 'query' | 'mutation', fieldName: string, args: {\n [key: string]: any;\n}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<any>;\ndelegateSubscription(fieldName: string, args?: {\n [key: string]: any;\n}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<AsyncIterator<any>>;\ngetAbstractResolvers(filterSchema?: GraphQLSchema | string): IResolvers;\n}\n\nexport interface BindingConstructor<T> {\n new(options: BPOType): T\n}\n/**\n * Type Defs\n*/\n\n", "\n\n", "\n\n/**\n * Types\n*/\n\n", ""])), this.renderImports(), this.renderQueries(), this.renderMutations(), this.renderSubscriptions(), this.renderExists(), this.renderTypedefs(), this.renderExports(), this.renderTypes());
30 };
31 PrismaFlowGenerator.prototype.renderImports = function () {
32 return "import type { GraphQLResolveInfo, GraphQLSchema } from 'graphql'\nimport type { IResolvers } from 'graphql-tools/dist/Interfaces'\nimport type { Options } from 'graphql-binding'\nimport type { BasePrismaOptions as BPOType } from 'prisma-binding'\nimport { makePrismaBindingClass, BasePrismaOptions } from 'prisma-binding'";
33 };
34 PrismaFlowGenerator.prototype.renderExports = function () {
35 return "const prisma: BindingConstructor<Prisma> = makePrismaBindingClass({typeDefs})\nexport { prisma as Prisma } \n";
36 };
37 PrismaFlowGenerator.prototype.renderTypedefs = function () {
38 return ('const typeDefs = `' + graphql_1.printSchema(this.schema).replace(/`/g, '\\`') + '`');
39 };
40 PrismaFlowGenerator.prototype.renderExists = function () {
41 var queryType = this.schema.getQueryType();
42 if (queryType) {
43 return "{\n" + utils_1.getExistsFlowTypes(queryType) + "\n}";
44 }
45 return '{}';
46 };
47 return PrismaFlowGenerator;
48}(graphql_binding_1.FlowGenerator));
49exports.PrismaFlowGenerator = PrismaFlowGenerator;
50var templateObject_1;
51//# sourceMappingURL=PrismaFlowGenerator.js.map
\No newline at end of file