graphql-config-extension-graphcool
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -69,3 +69,3 @@ "use strict"; | ||
var _this = this; | ||
var allExtensions, newConfig, home, globalClusterCachePath, cache, globalConfigPath, env, _a, _b; | ||
var allExtensions, newConfig, home, env, _a, _b; | ||
return __generator(this, function (_c) { | ||
@@ -82,6 +82,3 @@ switch (_c.label) { | ||
home = os.homedir(); | ||
globalClusterCachePath = path.join(home, '.graphcool/cache.yml'); | ||
cache = new graphcool_yml_1.ClusterCache(globalClusterCachePath); | ||
globalConfigPath = path.join(home, '.graphcool/config.yml'); | ||
env = new graphcool_yml_1.Environment(globalConfigPath); | ||
env = new graphcool_yml_1.Environment(home); | ||
return [4 /*yield*/, env.load({})]; | ||
@@ -94,3 +91,3 @@ case 1: | ||
['extensions', 'endpoints']]; | ||
return [4 /*yield*/, getEndpointsFromPath(env, newConfig.extensions.graphcool, cache, cwd, envVars)]; | ||
return [4 /*yield*/, getEndpointsFromPath(env, newConfig.extensions.graphcool, cwd, envVars)]; | ||
case 2: | ||
@@ -111,3 +108,3 @@ _a.apply(void 0, _b.concat([_c.sent()])); | ||
['projects', projectName, 'extensions', 'endpoints']]; | ||
return [4 /*yield*/, getEndpointsFromPath(env, project.extensions.graphcool, cache, cwd, envVars)]; | ||
return [4 /*yield*/, getEndpointsFromPath(env, project.extensions.graphcool, cwd, envVars)]; | ||
case 1: | ||
@@ -129,7 +126,7 @@ _a.apply(void 0, _b.concat([_c.sent()])); | ||
exports.patchEndpointsToConfigData = patchEndpointsToConfigData; | ||
function getEndpointsFromPath(env, ymlPath, cache, cwd, envVars) { | ||
function getEndpointsFromPath(env, ymlPath, cwd, envVars) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var joinedYmlPath, definition, serviceName, entries; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var joinedYmlPath, definition, serviceName, stage, cluster, url, token, headers, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -140,26 +137,22 @@ joinedYmlPath = cwd ? path.join(cwd, ymlPath) : ymlPath; | ||
case 1: | ||
_a.sent(); | ||
_b.sent(); | ||
serviceName = definition.definition.service; | ||
entries = cache.getEntriesByService(serviceName); | ||
if (envVars && envVars.GRAPHCOOL_STAGE) { | ||
entries = entries.filter(function (entry) { return entry.stage === envVars.GRAPHCOOL_STAGE; }); | ||
stage = definition.definition.stage; | ||
cluster = definition.getCluster(); | ||
if (!cluster) { | ||
throw new Error("No cluster set. Please set the \"cluster\" property in your graphcool.yml"); | ||
} | ||
return [2 /*return*/, entries.reduce(function (acc, entry) { | ||
var cluster = env.clusterByName(entry.cluster); | ||
if (cluster) { | ||
var url = cluster.getApiEndpoint(definition.definition.service, entry.stage); | ||
var token = definition.getToken(definition.definition.service, entry.stage); | ||
var headers = token | ||
? { | ||
Authorization: "Bearer " + token, | ||
} | ||
: undefined; | ||
return __assign({}, acc, (_a = {}, _a[entry.stage] = { | ||
url: url, | ||
headers: headers, | ||
}, _a)); | ||
} | ||
return acc; | ||
var _a; | ||
}, {})]; | ||
url = cluster.getApiEndpoint(serviceName, stage); | ||
token = definition.getToken(serviceName, stage); | ||
headers = token | ||
? { | ||
Authorization: "Bearer " + token, | ||
} | ||
: undefined; | ||
return [2 /*return*/, (_a = {}, | ||
_a[stage] = { | ||
url: url, | ||
headers: headers, | ||
}, | ||
_a)]; | ||
} | ||
@@ -166,0 +159,0 @@ }); |
{ | ||
"name": "graphql-config-extension-graphcool", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"graphcool-yml": "^0.1.7", | ||
"graphcool-yml": "0.2.1", | ||
"graphql-config": "^1.1.4" | ||
@@ -13,0 +11,0 @@ }, |
# graphql-config-extension-graphcool | ||
[![npm version](https://badge.fury.io/js/graphql-config-extension-graphcool.svg)](https://badge.fury.io/js/graphql-config-extension-graphcool) [![Build Status](https://travis-ci.org/graphcool/graphql-config-extension-graphcool.svg?branch=master)](https://travis-ci.org/graphcool/graphql-config-extension-graphcool) | ||
[![CircleCI](https://circleci.com/gh/graphcool/graphql-config-extension-graphcool.svg?style=shield)](https://circleci.com/gh/graphcool/graphql-config-extension-graphcool) [![npm version](https://badge.fury.io/js/graphql-config-extension-graphcool.svg)](https://badge.fury.io/js/graphql-config-extension-graphcool) | ||
@@ -5,0 +5,0 @@ Injects endpoints and headers into a GraphQL Config instance based on a given graphcool.yml |
Sorry, the diff of this file is not supported yet
16865
225
+ Addedgraphcool-yml@0.2.1(transitive)
- Removedgraphcool-yml@0.1.10(transitive)
Updatedgraphcool-yml@0.2.1