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 = 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(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 | if (service)
|
48 | configs.push(new ServiceConfig(this.rawConfig, this.configURI));
|
49 | return configs;
|
50 | }
|
51 | set variant(variant) {
|
52 | this._variant = variant;
|
53 | }
|
54 | get variant() {
|
55 | if (this._variant)
|
56 | return this._variant;
|
57 | let tag = "current";
|
58 | if (this.client && typeof this.client.service === "string") {
|
59 | const parsedVariant = utils_1.parseServiceSpecifier(this.client.service)[1];
|
60 | if (parsedVariant)
|
61 | tag = parsedVariant;
|
62 | }
|
63 | else if (this.service && typeof this.service.name === "string") {
|
64 | const parsedVariant = utils_1.parseServiceSpecifier(this.service.name)[1];
|
65 | if (parsedVariant)
|
66 | tag = parsedVariant;
|
67 | }
|
68 | return tag;
|
69 | }
|
70 | set graph(graphId) {
|
71 | this._graphId = graphId;
|
72 | }
|
73 | get graph() {
|
74 | if (this._graphId)
|
75 | return this._graphId;
|
76 | return utils_1.getGraphIdFromConfig(this.rawConfig);
|
77 | }
|
78 | setDefaults({ client, engine, service }) {
|
79 | const config = lodash_merge_1.default(this.rawConfig, { client, engine, service });
|
80 | this.rawConfig = config;
|
81 | this.client = config.client;
|
82 | this.service = config.service;
|
83 | if (engine)
|
84 | this.engine = config.engine;
|
85 | }
|
86 | }
|
87 | exports.ApolloConfig = ApolloConfig;
|
88 | class ClientConfig extends ApolloConfig {
|
89 | }
|
90 | exports.ClientConfig = ClientConfig;
|
91 | class ServiceConfig extends ApolloConfig {
|
92 | }
|
93 | exports.ServiceConfig = ServiceConfig;
|
94 |
|
\ | No newline at end of file |