New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-compose-modules

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-compose-modules - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

41

lib/astToSchema.js

@@ -87,3 +87,3 @@ "use strict";

parent.addNestedFields((_a = {},
_a[name] = prepareFieldConfig(ast),
_a[name] = ast.fieldConfig,
_a));

@@ -133,6 +133,3 @@ return;

function prepareNamespaceFieldConfig(sc, ast, typename) {
if (!ast.code.default) {
throw new Error((0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => ({}),\n };\n "], ["\n NamespaceModule MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'SomeObjectTypeName',\n resolve: () => ({}),\n };\n "])), ast.absPath));
}
var fc = ast.code.default;
var fc = ast.fieldConfig;
if (!fc.type) {

@@ -144,3 +141,3 @@ fc.type = sc.createObjectTC(typename);

if (!(0, graphql_compose_1.isOutputTypeDefinitionString)(fc.type) && !(0, graphql_compose_1.isWrappedTypeNameString)(fc.type)) {
throw new Error((0, dedent_1.default)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "], ["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "])), fc.type));
throw new Error((0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "], ["\n You provide incorrect output type definition:\n ", "\n It must be valid TypeName or output type SDL definition:\n \n Eg.\n type Payload { me: String }\n OR\n Payload\n "])), fc.type));
}

@@ -150,3 +147,3 @@ }

!(fc.type instanceof graphql_1.GraphQLObjectType)) {
throw new Error((0, dedent_1.default)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n You provide some strange value as 'type':\n ", "\n "], ["\n You provide some strange value as 'type':\n ", "\n "])), (0, graphql_compose_1.inspect)(fc.type)));
throw new Error((0, dedent_1.default)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n You provide some strange value as 'type':\n ", "\n "], ["\n You provide some strange value as 'type':\n ", "\n "])), (0, graphql_compose_1.inspect)(fc.type)));
}

@@ -160,31 +157,3 @@ fc.type = sc.createObjectTC(fc.type);

}
function prepareFieldConfig(ast) {
var fc = ast.code.default;
if (!fc) {
throw new Error((0, dedent_1.default)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "], ["\n Module MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "])), ast.absPath));
}
if (!fc.type || !isSomeOutputTypeDefinition(fc.type)) {
throw new Error((0, dedent_1.default)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "], ["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "])), ast.absPath));
}
return fc;
}
function isSomeOutputTypeDefinition(type) {
if (typeof type === 'string') {
// type: 'String'
return (0, graphql_compose_1.isSomeOutputTypeDefinitionString)(type) || (0, graphql_compose_1.isWrappedTypeNameString)(type);
}
else if (Array.isArray(type)) {
// type: ['String']
return isSomeOutputTypeDefinition(type[0]);
}
else if ((0, graphql_compose_1.isFunction)(type)) {
// pass thunked type without internal checks
return true;
}
else {
// type: 'type User { name: String }'
return (0, graphql_compose_1.isComposeOutputType)(type);
}
}
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=astToSchema.js.map

6

lib/directoryToAst.d.ts

@@ -27,2 +27,8 @@ /// <reference types="node" />

};
/**
* This FieldConfig loaded from `code` and validated.
* This property is used by ast transformers and stores the last version of modified config.
* This value will be used by astToSchema method.
*/
fieldConfig: FieldConfig;
}

@@ -29,0 +35,0 @@ export declare type RootTypeNames = 'query' | 'mutation' | 'subscription';

"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {

@@ -19,2 +23,3 @@ __assign = Object.assign || function(t) {

var fs_1 = __importDefault(require("fs"));
var graphql_compose_1 = require("graphql-compose");
var path_1 = require("path");

@@ -139,2 +144,6 @@ exports.defaultOptions = {

var moduleName = filename.substring(0, filename.lastIndexOf('.'));
// namespace configs may not have `type` property
var checkType = moduleName !== 'index';
var code = m.require(absPath);
var fieldConfig = prepareFieldConfig(code, absPath, checkType);
return {

@@ -144,3 +153,4 @@ kind: 'file',

absPath: absPath,
code: m.require(absPath),
code: code,
fieldConfig: fieldConfig,
};

@@ -197,2 +207,46 @@ }

}
function prepareFieldConfig(code, absPath, checkType) {
if (checkType === void 0) { checkType = true; }
var _fc = code === null || code === void 0 ? void 0 : code.default;
if (!_fc || typeof _fc !== 'object') {
throw new Error((0, graphql_compose_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n GraphQL entrypoint MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "], ["\n GraphQL entrypoint MUST return FieldConfig as default export in '", "'. \n Eg:\n export default {\n type: 'String',\n resolve: () => Date.now(),\n };\n "])), absPath));
}
var fc;
if (code.default instanceof graphql_compose_1.Resolver) {
fc = code.default.getFieldConfig();
}
else {
// recreate object for immutability purposes (do not change object in module definition)
// NB. I don't know should we here recreate (args, extensions) but let's keep them as is for now.
fc = __assign({}, code.default);
}
if (checkType) {
if (!fc.type || !isSomeOutputTypeDefinition(fc.type)) {
throw new Error((0, graphql_compose_1.dedent)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "], ["\n Module MUST return FieldConfig with correct 'type: xxx' property in '", "'. \n Eg:\n export default {\n type: 'String'\n };\n "])), absPath));
}
}
if (fc.resolve && typeof fc.resolve !== 'function') {
throw new Error("Cannot load entrypoint config from " + absPath + ". 'resolve' property must be a function or undefined.");
}
return fc;
}
function isSomeOutputTypeDefinition(type) {
if (typeof type === 'string') {
// type: 'String'
return (0, graphql_compose_1.isSomeOutputTypeDefinitionString)(type) || (0, graphql_compose_1.isWrappedTypeNameString)(type);
}
else if (Array.isArray(type)) {
// type: ['String']
return isSomeOutputTypeDefinition(type[0]);
}
else if ((0, graphql_compose_1.isFunction)(type)) {
// pass thunked type without internal checks
return true;
}
else {
// type: 'type User { name: String }'
return (0, graphql_compose_1.isComposeOutputType)(type);
}
}
var templateObject_1, templateObject_2;
//# sourceMappingURL=directoryToAst.js.map

@@ -82,3 +82,3 @@ "use strict";

if (!argNames.includes(varName)) {
throw new Error("FieldConfig does not have '" + varName + "' argument. Avaliable arguments: '" + argNames.join("', '") + "'.");
throw new Error("FieldConfig does not have '" + varName + "' argument. Available arguments: '" + argNames.join("', '") + "'.");
}

@@ -85,0 +85,0 @@ });

@@ -93,9 +93,10 @@ "use strict";

get: function () {
var _a, _b, _c;
var _a;
var node = this.node;
if (node.kind === 'file') {
return (_a = node.code) === null || _a === void 0 ? void 0 : _a.default;
return node.fieldConfig;
}
else if (node.kind === 'dir' || this.node.kind === 'rootType') {
return (_c = (_b = node.namespaceConfig) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.default;
// TODO: think about namespaceConfig (how to do it not null)
return (_a = node.namespaceConfig) === null || _a === void 0 ? void 0 : _a.fieldConfig;
}

@@ -102,0 +103,0 @@ throw new Error("Cannot get fieldConfig. Node has some strange kind: " + node.kind);

{
"name": "graphql-compose-modules",
"license": "MIT",
"version": "2.0.0",
"version": "3.0.0",
"description": "A toolkit for construction GraphQL Schema via file structure",

@@ -6,0 +6,0 @@ "repository": "https://github.com/graphql-compose/graphql-compose-modules",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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