Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-config

Package Overview
Dependencies
Maintainers
3
Versions
320
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-config - npm Package Compare versions

Comparing version 1.0.0-rc.8 to 1.0.0-rc.9

7

lib/extensions/endpoints/EndpointsExtension.d.ts

@@ -23,3 +23,3 @@ import { GraphQLClient } from 'graphql-request';

};
export declare type GraphQLConfigEnpointsData = GraphQLConfigEnpointsMap;
export declare type GraphQLConfigEnpointsData = GraphQLConfigEnpointsMapData;
export declare class GraphQLEndpointsExtension {

@@ -30,6 +30,7 @@ raw: GraphQLConfigEnpointsMapData;

getRawEndpointsMap(): GraphQLConfigEnpointsMap;
getEnvVarsForEndpoint(endpointName?: string): {
private getRawEndpoint(endpointName?);
getEnvVarsForEndpoint(endpointName: string): {
[name: string]: string | null;
};
getEndpoint(endpointName?: string, env?: {
getEndpoint(endpointName: string, env?: {
[name: string]: string;

@@ -36,0 +37,0 @@ }): GraphQLEndpoint;

@@ -55,26 +55,30 @@ "use strict";

GraphQLEndpointsExtension.prototype.getRawEndpointsMap = function () {
var endpoints = this.raw;
return valuesMap(endpoints, function (value) {
if (typeof value === 'string') {
return { url: value };
var endpoints = {};
for (var name_1 in this.raw) {
var rawEndpoint = this.raw[name_1];
if (typeof rawEndpoint === 'string') {
endpoints[name_1] = { url: rawEndpoint };
}
return value;
});
else {
endpoints[name_1] = rawEndpoint;
}
}
return endpoints;
};
GraphQLEndpointsExtension.prototype.getEnvVarsForEndpoint = function (endpointName) {
GraphQLEndpointsExtension.prototype.getRawEndpoint = function (endpointName) {
if (endpointName === void 0) { endpointName = process.env.GRAPHQL_CONFIG_ENDPOINT_NAME; }
var endpoint = this.getRawEndpointsMap()[endpointName];
if (!endpoint || !endpoint.url) {
throw new Error(this.configPath + ": \"" + endpointName + "\" is not valid endpoint name. Valid endpoint names: " +
Object.keys(this.getRawEndpointsMap()).join(', '));
var rawEndpointsMap = this.getRawEndpointsMap();
var endpointNames = Object.keys(rawEndpointsMap);
if (endpointName == null) {
if (endpointNames.length === 1) {
endpointName = endpointNames[0];
}
else {
throw new Error("You have to specify endpoint name or define GRAPHQL_CONFIG_ENDPOINT_NAME enviroment variable");
}
}
return resolveRefString_1.getUsedEnvs(endpoint);
};
GraphQLEndpointsExtension.prototype.getEndpoint = function (endpointName, env) {
if (endpointName === void 0) { endpointName = process.env.GRAPHQL_CONFIG_ENDPOINT_NAME; }
if (env === void 0) { env = process.env; }
var endpoint = this.getRawEndpointsMap()[endpointName];
var endpoint = rawEndpointsMap[endpointName];
if (!endpoint) {
throw new Error(this.configPath + ": \"" + endpointName + "\" is not valid endpoint name. Valid endpoint names: " +
Object.keys(this.getRawEndpointsMap()).join(', '));
throw new Error(this.configPath + ": \"" + endpointName + "\" is not valid endpoint name. " +
("Valid endpoint names: " + endpointNames.join(', ')));
}

@@ -84,2 +88,10 @@ if (!endpoint.url) {

}
return endpoint;
};
GraphQLEndpointsExtension.prototype.getEnvVarsForEndpoint = function (endpointName) {
return resolveRefString_1.getUsedEnvs(this.getRawEndpoint(endpointName));
};
GraphQLEndpointsExtension.prototype.getEndpoint = function (endpointName, env) {
if (env === void 0) { env = process.env; }
var endpoint = this.getRawEndpoint(endpointName);
try {

@@ -89,3 +101,2 @@ return new GraphQLEndpoint(resolveRefString_1.resolveEnvsInValues(endpoint, env));

catch (e) {
// prefix error
e.message = this.configPath + ": " + e.message;

@@ -150,8 +161,1 @@ throw e;

exports.GraphQLEndpoint = GraphQLEndpoint;
function valuesMap(obj, fn) {
var res = {};
for (var key in obj) {
res[key] = fn(obj[key]);
}
return res;
}

@@ -14,2 +14,3 @@ import { GraphQLConfigData } from './types';

};
saveConfig(newConfig: GraphQLConfigData, projectName?: string): void;
}

@@ -41,4 +41,17 @@ "use strict";

};
GraphQLConfig.prototype.saveConfig = function (newConfig, projectName) {
var config;
if (projectName) {
config = this.config;
config.projects = config.projects || {};
config.projects[projectName] = config.projects[projectName] || {};
config.projects[projectName] = newConfig;
}
else {
config = newConfig;
}
utils_1.writeConfig(this.configPath, config);
};
return GraphQLConfig;
}());
exports.GraphQLConfig = GraphQLConfig;

@@ -129,2 +129,5 @@ "use strict";

get: function () {
if (!this.extensions.endpoints) {
return null;
}
var endpoints = this.extensions.endpoints;

@@ -134,4 +137,6 @@ if (typeof endpoints !== 'object' || Array.isArray(endpoints)) {

}
return endpoints && Object.keys(endpoints).length !== 0 ?
new extensions_1.GraphQLEndpointsExtension(this.extensions.endpoints, this.configPath) : null;
if (Object.keys(endpoints).length === 0) {
return null;
}
return new extensions_1.GraphQLEndpointsExtension(this.extensions.endpoints, this.configPath);
},

@@ -138,0 +143,0 @@ enumerable: true,

export { getGraphQLConfig, getGraphQLProjectConfig } from './getGraphQLConfig';
export { GRAPHQL_CONFIG_NAME, GRAPHQL_CONFIG_YAML_NAME, findGraphQLConfigFile } from './findGraphQLConfigFile';
export { writeSchema, validateConfig } from './utils';
export { writeSchema, validateConfig, getSchemaExtensions } from './utils';
export * from './errors';

@@ -5,0 +5,0 @@ export * from './extensions/';

@@ -16,2 +16,3 @@ "use strict";

exports.validateConfig = utils_1.validateConfig;
exports.getSchemaExtensions = utils_1.getSchemaExtensions;
__export(require("./errors"));

@@ -18,0 +19,0 @@ __export(require("./extensions/"));

@@ -5,6 +5,7 @@ import { IntrospectionQuery } from 'graphql';

data: IntrospectionQuery;
extensions?: Object;
errors?: any;
};
export declare type GraphQLConfigExtensions = {
endpoint?: GraphQLConfigEnpointsData;
endpoints?: GraphQLConfigEnpointsData;
[name: string]: any;

@@ -11,0 +12,0 @@ };

import { GraphQLSchema } from 'graphql';
import { GraphQLConfigData, IntrospectionResult } from './types';
export declare function readConfig(configPath: string): GraphQLConfigData;
export declare function writeConfig(configPath: string, config: GraphQLConfigData): void;
export declare function normalizeGlob(glob: string): string;

@@ -11,2 +12,7 @@ export declare function matchesGlobs(filePath: string, globs?: string[]): boolean;

export declare function readSchema(path: any): GraphQLSchema;
export declare function writeSchema(path: any, schema: any): Promise<void>;
export declare function writeSchema(path: string, schema: GraphQLSchema, schemaExtensions?: {
[name: string]: string;
}): Promise<void>;
export declare function getSchemaExtensions(path: string): {
[name: string]: string;
};

@@ -69,2 +69,13 @@ "use strict";

exports.readConfig = readConfig;
function writeConfig(configPath, config) {
var configContents;
if (configPath.endsWith('.yaml')) {
configContents = yaml.safeDump(config);
}
else {
configContents = JSON.stringify(config);
}
fs_1.writeFileSync(configPath, configContents, 'utf-8');
}
exports.writeConfig = writeConfig;
function normalizeGlob(glob) {

@@ -136,7 +147,7 @@ if (glob.startsWith('./')) {

}
function writeSchema(path, schema) {
function writeSchema(path, schema, schemaExtensions) {
return __awaiter(this, void 0, void 0, function () {
var data, _a, introspection;
return __generator(this, function (_b) {
switch (_b.label) {
var data, _a, name_1, introspection, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -151,7 +162,17 @@ schema = valueToSchema(schema);

case 1:
data = graphql_1.printSchema(schema);
data = '';
if (schemaExtensions) {
for (name_1 in schemaExtensions) {
data += "# " + name_1 + ": " + schemaExtensions[name_1];
}
data += '\n';
}
data += graphql_1.printSchema(schema);
return [3 /*break*/, 5];
case 2: return [4 /*yield*/, schemaToIntrospection(schema)];
case 3:
introspection = _b.sent();
introspection = _c.sent();
introspection.extensions = (_b = {},
_b['graphql-config'] = schemaExtensions,
_b);
data = JSON.stringify(introspection, null, 2);

@@ -168,1 +189,27 @@ return [3 /*break*/, 5];

exports.writeSchema = writeSchema;
function getSchemaExtensions(path) {
var data = fs_1.readFileSync(path, 'utf-8');
switch (path_1.extname(path)) {
case '.graphql':
var extensions = {};
for (var _i = 0, _a = data.split('\n'); _i < _a.length; _i++) {
var line = _a[_i];
var result = /# ([^:]+): (.+)$/.exec(line);
if (result == null) {
break;
}
var _ = result[0], key = result[1], value = result[2];
extensions[key] = value;
}
return extensions;
case '.json':
var introspection = JSON.parse(data);
if (!introspection.extentions) {
return {};
}
return introspection.extensions['graphql-config'] || {};
default:
throw new Error('Unsupported schema file extention. Only ".graphql" and ".json" are supported');
}
}
exports.getSchemaExtensions = getSchemaExtensions;
{
"name": "graphql-config",
"version": "1.0.0-rc.8",
"version": "1.0.0-rc.9",
"description": "The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc