UNPKG

4.6 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 PrismaTypescriptGenerator = /** @class */ (function (_super) {
24 __extends(PrismaTypescriptGenerator, _super);
25 function PrismaTypescriptGenerator(options) {
26 return _super.call(this, options) || this;
27 }
28 PrismaTypescriptGenerator.prototype.render = function () {
29 return this.compile(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", "\n\nexport interface Query ", "\n\nexport interface Mutation ", "\n\nexport interface Subscription ", "\n\nexport interface Exists ", "\n\nexport interface Prisma {\n query: Query\n mutation: Mutation\n subscription: Subscription\n exists: Exists\n request: <T = any>(query: string, variables?: {[key: string]: any}) => Promise<T>\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: BasePrismaOptions): T\n}\n/**\n * Type Defs\n*/\n\n", "\n\n", "\n\n/**\n * Types\n*/\n\n", ""], ["\\\n", "\n\nexport interface Query ", "\n\nexport interface Mutation ", "\n\nexport interface Subscription ", "\n\nexport interface Exists ", "\n\nexport interface Prisma {\n query: Query\n mutation: Mutation\n subscription: Subscription\n exists: Exists\n request: <T = any>(query: string, variables?: {[key: string]: any}) => Promise<T>\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: BasePrismaOptions): 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 PrismaTypescriptGenerator.prototype.renderImports = function () {
32 return "import { GraphQLResolveInfo, GraphQLSchema } from 'graphql'\nimport { IResolvers } from 'graphql-tools/dist/Interfaces'\nimport { Options } from 'graphql-binding'\nimport { makePrismaBindingClass, BasePrismaOptions } from 'prisma-binding'";
33 };
34 PrismaTypescriptGenerator.prototype.renderExports = function () {
35 return "export const Prisma = makePrismaBindingClass<BindingConstructor<Prisma>>({typeDefs})";
36 };
37 PrismaTypescriptGenerator.prototype.renderTypedefs = function () {
38 return ('const typeDefs = `' + graphql_1.printSchema(this.schema).replace(/`/g, '\\`') + '`');
39 };
40 PrismaTypescriptGenerator.prototype.renderExists = function () {
41 var queryType = this.schema.getQueryType();
42 if (queryType) {
43 return "{\n" + utils_1.getExistsTypes(queryType) + "\n}";
44 }
45 return '{}';
46 };
47 return PrismaTypescriptGenerator;
48}(graphql_binding_1.TypescriptGenerator));
49exports.PrismaTypescriptGenerator = PrismaTypescriptGenerator;
50var templateObject_1;
51//# sourceMappingURL=PrismaTypescriptGenerator.js.map
\No newline at end of file