1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.ServiceConfig = exports.ClientConfig = exports.ApolloConfig = exports.DefaultServiceConfig = exports.DefaultClientConfig = exports.DefaultConfigBase = exports.DefaultEngineConfig = exports.DefaultEngineStatsWindow = void 0;
|
7 | const path_1 = require("path");
|
8 | const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
9 | const vscode_uri_1 = __importDefault(require("vscode-uri"));
|
10 | const utils_1 = require("./utils");
|
11 | exports.DefaultEngineStatsWindow = {
|
12 | to: -0,
|
13 | from: -86400,
|
14 | };
|
15 | exports.DefaultEngineConfig = {
|
16 | endpoint: "https://graphql.api.apollographql.com/api/graphql",
|
17 | };
|
18 | exports.DefaultConfigBase = {
|
19 | includes: ["src/**/*.{ts,tsx,js,jsx,graphql,gql}"],
|
20 | excludes: ["**/node_modules", "**/__tests__"],
|
21 | };
|
22 | exports.DefaultClientConfig = Object.assign(Object.assign({}, exports.DefaultConfigBase), { tagName: "gql", clientOnlyDirectives: ["connection", "type"], clientSchemaDirectives: ["client", "rest"], addTypename: true, statsWindow: exports.DefaultEngineStatsWindow });
|
23 | exports.DefaultServiceConfig = Object.assign(Object.assign({}, exports.DefaultConfigBase), { endpoint: {
|
24 | url: "http://localhost:4000/graphql",
|
25 | } });
|
26 | class ApolloConfig {
|
27 | constructor(rawConfig, configURI) {
|
28 | this.rawConfig = rawConfig;
|
29 | this.configURI = configURI;
|
30 | this.isService = !!rawConfig.service;
|
31 | this.isClient = !!rawConfig.client;
|
32 | this.engine = rawConfig.engine;
|
33 | this._graphId = (0, utils_1.getGraphIdFromConfig)(rawConfig);
|
34 | this.client = rawConfig.client;
|
35 | this.service = rawConfig.service;
|
36 | }
|
37 | get configDirURI() {
|
38 | return this.configURI && this.configURI.fsPath.match(/\.(ts|js|json)$/i)
|
39 | ? vscode_uri_1.default.parse((0, path_1.dirname)(this.configURI.fsPath))
|
40 | : this.configURI;
|
41 | }
|
42 | get projects() {
|
43 | const configs = [];
|
44 | const { client, service } = this.rawConfig;
|
45 | if (client) {
|
46 | configs.push(new ClientConfig(this.rawConfig, this.configURI));
|
47 | }
|
48 | if (service) {
|
49 | configs.push(new ServiceConfig(this.rawConfig, this.configURI));
|
50 | }
|
51 | return configs;
|
52 | }
|
53 | set variant(variant) {
|
54 | this._variant = variant;
|
55 | }
|
56 | get variant() {
|
57 | if (this._variant)
|
58 | return this._variant;
|
59 | let tag = "current";
|
60 | if (this.client && typeof this.client.service === "string") {
|
61 | const parsedVariant = (0, utils_1.parseServiceSpecifier)(this.client.service)[1];
|
62 | if (parsedVariant)
|
63 | tag = parsedVariant;
|
64 | }
|
65 | else if (this.service && typeof this.service.name === "string") {
|
66 | const parsedVariant = (0, utils_1.parseServiceSpecifier)(this.service.name)[1];
|
67 | if (parsedVariant)
|
68 | tag = parsedVariant;
|
69 | }
|
70 | return tag;
|
71 | }
|
72 | set graph(graphId) {
|
73 | this._graphId = graphId;
|
74 | }
|
75 | get graph() {
|
76 | if (this._graphId)
|
77 | return this._graphId;
|
78 | return (0, utils_1.getGraphIdFromConfig)(this.rawConfig);
|
79 | }
|
80 | setDefaults({ client, engine, service }) {
|
81 | const config = (0, lodash_merge_1.default)(this.rawConfig, { client, engine, service });
|
82 | this.rawConfig = config;
|
83 | this.client = config.client;
|
84 | this.service = config.service;
|
85 | if (engine)
|
86 | this.engine = config.engine;
|
87 | }
|
88 | }
|
89 | exports.ApolloConfig = ApolloConfig;
|
90 | class ClientConfig extends ApolloConfig {
|
91 | }
|
92 | exports.ClientConfig = ClientConfig;
|
93 | class ServiceConfig extends ApolloConfig {
|
94 | }
|
95 | exports.ServiceConfig = ServiceConfig;
|
96 |
|
\ | No newline at end of file |