1 | "use strict";
|
2 | var __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 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | var graphql_binding_1 = require("graphql-binding");
|
28 | var jsonwebtoken_1 = require("jsonwebtoken");
|
29 | var link_1 = require("./link");
|
30 | var info_1 = require("./info");
|
31 | var SharedLink_1 = require("./SharedLink");
|
32 | var utils_1 = require("./utils");
|
33 | var cache_1 = require("./cache");
|
34 | var sharedLink = new SharedLink_1.SharedLink();
|
35 | var Prisma = (function (_super) {
|
36 | __extends(Prisma, _super);
|
37 | function Prisma(_a) {
|
38 | var typeDefs = _a.typeDefs, endpoint = _a.endpoint, secret = _a.secret, fragmentReplacements = _a.fragmentReplacements, debug = _a.debug, disableCache = _a.disableCache;
|
39 | var _this = this;
|
40 | if (!typeDefs) {
|
41 | throw new Error('No `typeDefs` provided when calling `new Prisma()`');
|
42 | }
|
43 | if (typeDefs.endsWith('.graphql')) {
|
44 | typeDefs = cache_1.getCachedTypeDefs(typeDefs, disableCache);
|
45 | }
|
46 | if (endpoint === undefined) {
|
47 | throw new Error("No Prisma endpoint found. Please provide the `endpoint` constructor option.");
|
48 | }
|
49 | if (!endpoint.startsWith('http')) {
|
50 | throw new Error("Invalid Prisma endpoint provided: " + endpoint);
|
51 | }
|
52 | fragmentReplacements = fragmentReplacements || [];
|
53 | debug = debug || false;
|
54 | var token = secret ? jsonwebtoken_1.sign({}, secret) : undefined;
|
55 | var link = link_1.makePrismaLink({ endpoint: endpoint, token: token, debug: debug });
|
56 | var remoteSchema = cache_1.getCachedRemoteSchema(endpoint, typeDefs, sharedLink, disableCache);
|
57 | var before = function () {
|
58 | sharedLink.setInnerLink(link);
|
59 | };
|
60 | _this = _super.call(this, {
|
61 | schema: remoteSchema,
|
62 | fragmentReplacements: fragmentReplacements,
|
63 | before: before,
|
64 | disableCache: disableCache,
|
65 | }) || this;
|
66 | _this.exists = _this.buildExists();
|
67 | return _this;
|
68 | }
|
69 | Prisma.prototype.buildExists = function () {
|
70 | var _this = this;
|
71 | var queryType = this.schema.getQueryType();
|
72 | if (!queryType) {
|
73 | return {};
|
74 | }
|
75 | if (queryType) {
|
76 | var types = utils_1.getTypesAndWhere(queryType);
|
77 | return types.reduce(function (acc, _a) {
|
78 | var _b;
|
79 | var type = _a.type, pluralFieldName = _a.pluralFieldName;
|
80 | return __assign({}, acc, (_b = {}, _b[type] = function (args) {
|
81 | return _this.delegate('query', pluralFieldName, { where: args }, info_1.buildExistsInfo(pluralFieldName, _this.schema)).then(function (res) { return res.length > 0; });
|
82 | }, _b));
|
83 | }, {});
|
84 | }
|
85 | return {};
|
86 | };
|
87 | return Prisma;
|
88 | }(graphql_binding_1.Binding));
|
89 | exports.Prisma = Prisma;
|
90 |
|
\ | No newline at end of file |