Socket
Socket
Sign inDemoInstall

simple-graphql

Package Overview
Dependencies
Maintainers
1
Versions
300
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-graphql - npm Package Compare versions

Comparing version 5.1.6 to 5.2.0

dist/build/buildRootSubscription.d.ts

19

dist/build/buildFieldTypeContext.js

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

interfaces: [context.interface('Node')],
fields: () => (0, toGraphQLFieldConfigMap_1.default)(typeName, '', Object.assign(Object.assign({ id: {
fields: () => toGraphQLFieldConfigMap_1.default(typeName, '', Object.assign(Object.assign({ id: {
type: 'Id',

@@ -82,2 +82,3 @@ nullable: false,

hookQueryResolve: (name, options) => context.hookQueryResolve(name, options),
hookSubscriptionResolve: (name, options) => context.hookSubscriptionResolve(name, options),
hookMutationResolve: (name, options) => context.hookMutationResolve(name, options),

@@ -151,3 +152,3 @@ typeConfig: (typeName) => fieldTypeContext.typeConfig(typeName)

const typeName = schema.name + 'Id';
const idType = (0, globalIdType_1.default)(schema.name);
const idType = globalIdType_1.default(schema.name);
return {

@@ -163,5 +164,6 @@ name: typeName,

const toOutputType = (name, options) => {
const outputConfigMap = (0, toGraphQLFieldConfigMap_1.default)(name, '', { '': options }, {
const outputConfigMap = toGraphQLFieldConfigMap_1.default(name, '', { '': options }, {
hookFieldResolve: (name, options) => context.hookFieldResolve(name, options),
hookQueryResolve: (name, options) => context.hookQueryResolve(name, options),
hookSubscriptionResolve: (name, options) => context.hookSubscriptionResolve(name, options),
hookMutationResolve: (name, options) => context.hookMutationResolve(name, options),

@@ -173,3 +175,3 @@ typeConfig: (typeName) => fieldTypeContext.typeConfig(typeName)

const toInputType = (name, options) => {
const inputConfigMap = (0, toGraphQLInputFieldConfigMap_1.default)(name, { '': options }, fieldTypeContext)[''];
const inputConfigMap = toGraphQLInputFieldConfigMap_1.default(name, { '': options }, fieldTypeContext)[''];
return inputConfigMap && inputConfigMap.type;

@@ -247,7 +249,6 @@ };

type: typeConfig.outputType,
resolve: (typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.outputResolve)
? context.hookFieldResolve('value', {
output: { type: wrapType },
resolve: typeConfig.outputResolve
})
resolve: (typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.outputResolve) ? context.hookFieldResolve('value', {
output: { type: wrapType },
resolve: typeConfig.outputResolve
})
: undefined

@@ -254,0 +255,0 @@ }

@@ -6,4 +6,4 @@ "use strict";

const interfaces = {
Node: (0, graphql_relay_1.nodeDefinitions)((globalId) => {
const { type, id } = (0, graphql_relay_1.fromGlobalId)(globalId);
Node: graphql_relay_1.nodeDefinitions((globalId) => {
const { type, id } = graphql_relay_1.fromGlobalId(globalId);
console.log('Warning-------------------- node id Fetcher not implement' +

@@ -10,0 +10,0 @@ type +

@@ -1,3 +0,3 @@

import { SGHookConfig, SGResolverContext, SGContext } from '..';
import { SGContext, SGHookConfig, SGResolverContext } from '..';
declare const _default: (hooks: Array<SGHookConfig>, sgContext: SGContext) => SGResolverContext;
export default _default;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -60,2 +69,17 @@ exports.default = (hooks, sgContext) => {

},
hookSubscriptionResolve: (name, options) => {
const target = {
type: 'subscription',
name: name,
targetConfig: options
};
const hookFunc = applyHooks(target);
return (source, args, context, info) => hookFunc(target, {
source: source,
args: args,
context: context,
info: info,
sgContext: sgContext
}, () => __awaiter(void 0, void 0, void 0, function* () { return options.subscribe(args, context, info, sgContext); }));
},
hookMutationResolve: (name, options) => {

@@ -62,0 +86,0 @@ const target = {

@@ -17,6 +17,6 @@ "use strict";

}
const inputFields = (0, toGraphQLInputFieldConfigMap_1.default)(StringHelper_1.default.toInitialUpperCase(name), options.input || {}, context);
const outputFields = (0, toGraphQLFieldConfigMap_1.default)(name, 'Payload', options.output || {}, context);
const inputFields = toGraphQLInputFieldConfigMap_1.default(StringHelper_1.default.toInitialUpperCase(name), options.input || {}, context);
const outputFields = toGraphQLFieldConfigMap_1.default(name, 'Payload', options.output || {}, context);
const payloadFields = lodash_1.default.get(options, 'mutation.payloadFields', []);
mutations[name] = (0, mutationWithClientMutationId_1.default)({
mutations[name] = mutationWithClientMutationId_1.default({
name: StringHelper_1.default.toInitialUpperCase(name),

@@ -23,0 +23,0 @@ inputFields: inputFields,

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

}
const fieldConfig = (0, toGraphQLFieldConfigMap_1.default)(name, 'Payload', { '': options.output }, context)[''];
const fieldConfig = toGraphQLFieldConfigMap_1.default(name, 'Payload', { '': options.output }, context)[''];
const finalOptions = Object.assign({}, options);

@@ -66,3 +66,3 @@ const fieldResolve = fieldConfig.resolve;

if (options.input || fieldConfig.args) {
queries[name].args = Object.assign(Object.assign({}, fieldConfig.args), (0, toGraphQLInputFieldConfigMap_1.default)(StringHelper_1.default.toInitialUpperCase(name), Object.assign({}, options.input), context));
queries[name].args = Object.assign(Object.assign({}, fieldConfig.args), toGraphQLInputFieldConfigMap_1.default(StringHelper_1.default.toInitialUpperCase(name), Object.assign({}, options.input), context));
}

@@ -69,0 +69,0 @@ };

@@ -20,7 +20,8 @@ "use strict";

const buildRootMutations_1 = __importDefault(require("./buildRootMutations"));
const buildRootSubscription_1 = __importDefault(require("./buildRootSubscription"));
function buildGraphQLContext(sequelize, config, buildOptions) {
const plugins = (0, buildPlugins_1.default)(config.plugins || []);
const plugins = buildPlugins_1.default(config.plugins || []);
const sgContext = {
sequelize: sequelize,
schemas: (0, applyPluginsToSchemas_1.default)(config.schemas || [], plugins, config, buildOptions),
schemas: applyPluginsToSchemas_1.default(config.schemas || [], plugins, config, buildOptions),
models: {},

@@ -30,7 +31,8 @@ services: {},

};
const resolveContext = (0, buildResolverContext_1.default)(config.hooks || [], sgContext);
const interfaceContext = (0, buildInterfaceContext_1.default)(sgContext);
const resolveContext = buildResolverContext_1.default(config.hooks || [], sgContext);
const interfaceContext = buildInterfaceContext_1.default(sgContext);
const context = {
hookFieldResolve: (name, options) => resolveContext.hookFieldResolve(name, options),
hookQueryResolve: (name, options) => resolveContext.hookQueryResolve(name, options),
hookSubscriptionResolve: (name, options) => resolveContext.hookSubscriptionResolve(name, options),
hookMutationResolve: (name, options) => resolveContext.hookMutationResolve(name, options),

@@ -45,10 +47,10 @@ interface: (str) => {

};
const fieldTypeContext = (0, buildFieldTypeContext_1.default)(config.types || [], config.dataTypes || [], config.schemas || [], context);
const fieldTypeContext = buildFieldTypeContext_1.default(config.types || [], config.dataTypes || [], config.schemas || [], context);
context.typeConfig = (typeName) => fieldTypeContext.typeConfig(typeName);
sgContext.typeConfig = (typeName) => fieldTypeContext.typeConfig(typeName);
sgContext.models = (0, applyPluginsToModels_1.default)((0, buildSequelizeModels_1.default)(sequelize, (config.schemas || []).filter((s) => {
sgContext.models = applyPluginsToModels_1.default(buildSequelizeModels_1.default(sequelize, (config.schemas || []).filter((s) => {
return s instanceof __1.SGSchema;
}), sgContext), plugins, buildOptions.defaultPlugin || {});
sgContext.services = (0, buildServices_1.default)(config.services || [], sgContext);
const rootQueries = (0, buildRootQueries_1.default)([
sgContext.services = buildServices_1.default(config.services || [], sgContext);
const rootQueries = buildRootQueries_1.default([
...(config.schemas || []).map((schema) => schema.config.queries),

@@ -72,3 +74,3 @@ config.queries || {}

}
const rootMutations = (0, buildRootMutations_1.default)([
const rootMutations = buildRootMutations_1.default([
...(config.schemas || []).map((schema) => schema.config.mutations),

@@ -83,2 +85,12 @@ config.mutations || {}

}
const rootSubscriptions = buildRootSubscription_1.default([
...(config.schemas || []).map((schema) => schema.config.subscriptions),
config.subscriptions || {}
], context);
if (lodash_1.default.keys(rootSubscriptions).length > 0) {
schemaConfig.subscription = new graphql_1.GraphQLObjectType({
name: 'RootSubscription',
fields: () => rootSubscriptions
});
}
return {

@@ -85,0 +97,0 @@ sgContext: sgContext,

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

});
const key = `${dbModel.name}.findByPk|${(0, getFindOptionsKey_1.default)(dbModel, option)}`;
const key = `${dbModel.name}.findByPk|${getFindOptionsKey_1.default(dbModel, option)}`;
if (!context.dataloaderMap[key]) {

@@ -34,0 +34,0 @@ context.dataloaderMap[key] = new dataloader_1.default(function (ids) {

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

maxBatchSize: 1,
cacheKeyFn: (k) => (0, getFindOptionsKey_1.default)(dbModel, k)
cacheKeyFn: (k) => getFindOptionsKey_1.default(dbModel, k)
});

@@ -44,0 +44,0 @@ }

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

if (typeof value === 'string') {
return (0, graphql_relay_1.toGlobalId)(typeName, value);
return graphql_relay_1.toGlobalId(typeName, value);
}

@@ -20,3 +20,3 @@ else {

if (typeof value === 'string') {
const { type, id } = (0, graphql_relay_1.fromGlobalId)(value);
const { type, id } = graphql_relay_1.fromGlobalId(value);
if (type === typeName) {

@@ -43,3 +43,3 @@ if (Number.parseInt(id).toString() === id) {

if (typeof value === 'string') {
const { type, id } = (0, graphql_relay_1.fromGlobalId)(value);
const { type, id } = graphql_relay_1.fromGlobalId(value);
if (type === typeName) {

@@ -46,0 +46,0 @@ if (Number.parseInt(id).toString() === id) {

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

}
const value = (0, graphql_1.coerceInputValue)(inputValue[valueKey], valueType);
const value = graphql_1.coerceInputValue(inputValue[valueKey], valueType);
return {

@@ -76,3 +76,3 @@ [typeKey]: inputValue[typeKey],

//if (isValidLiteralValue(inputType, ast).length === 0) {
return (0, graphql_1.valueFromAST)(ast, inputType);
return graphql_1.valueFromAST(ast, inputType);
// } else {

@@ -79,0 +79,0 @@ // throw new GraphQLError(

@@ -1,2 +0,2 @@

import { SGColumnFieldConfigMap, SGLinkedFieldConfigMap, SGMutationConfigMap, SGQueryConfigMap, BaseSGSchemaOptions } from '..';
import { BaseSGSchemaOptions, SGColumnFieldConfigMap, SGLinkedFieldConfigMap, SGMutationConfigMap, SGQueryConfigMap, SGSubscriptionConfigMap } from '..';
export declare class BaseSGSchema {

@@ -8,2 +8,3 @@ name: string;

queries: SGQueryConfigMap;
subscriptions: SGSubscriptionConfigMap;
mutations: SGMutationConfigMap;

@@ -33,2 +34,6 @@ methods: {

/**
* Add the GraphQL subscription methods.
*/
subscriptions<T extends BaseSGSchema>(this: T, subscriptions: SGSubscriptionConfigMap): T;
/**
* Add the GraphQL mutataion methods.

@@ -35,0 +40,0 @@ */

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

queries: {},
subscriptions: {},
mutations: {},

@@ -42,2 +43,10 @@ methods: {},

/**
* Add the GraphQL subscription methods.
*/
subscriptions(subscriptions) {
// TODO duplicate check
this.config.subscriptions = Object.assign(this.config.subscriptions, subscriptions);
return this;
}
/**
* Add the GraphQL mutataion methods.

@@ -44,0 +53,0 @@ */

import Sequelize, { BelongsToManyOptions, BelongsToOptions, HasManyOptions, HasOneOptions, OrderItem } from 'sequelize';
import { SGSchemaOptions, SGColumnFieldConfigMap, SGHookOptionsMap, SGInputFieldConfigMap, SGLinkedFieldConfigMap, SGMutationConfigMap, SGQueryConfigMap } from '../index';
import { SGSchemaOptions, SGColumnFieldConfigMap, SGHookOptionsMap, SGInputFieldConfigMap, SGLinkedFieldConfigMap, SGMutationConfigMap, SGQueryConfigMap, SGSubscriptionConfigMap } from '../index';
import { BaseSGSchema } from './BaseSGSchema';

@@ -66,2 +66,3 @@ /**

queries: SGQueryConfigMap;
subscriptions: SGSubscriptionConfigMap;
mutations: SGMutationConfigMap;

@@ -68,0 +69,0 @@ methods: {

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

queries: {},
subscriptions: {},
mutations: {},

@@ -24,0 +25,0 @@ methods: {},

@@ -25,3 +25,3 @@ import { GraphQLFieldResolver, GraphQLInputType, GraphQLInterfaceType, GraphQLOutputType, GraphQLResolveInfo } from 'graphql';

findByPkForGraphQL: typeof findByPkForGraphQL;
withCache: <T, M extends SGModel<T>>(this: {
withCache: <T extends {}, M extends SGModel<T>>(this: {
new (): M;

@@ -60,2 +60,3 @@ } & typeof Model) => {

hookQueryResolve: (path: string, config: SGQueryConfig) => GraphQLFieldResolver<any, any>;
hookSubscriptionResolve: (path: string, config: SGSubscriptionConfig) => GraphQLFieldResolver<any, any>;
hookMutationResolve: (path: string, config: SGMutationConfig) => GraphQLFieldResolver<any, any>;

@@ -224,2 +225,15 @@ };

};
export declare type SGSubscriptionConfig<T = any> = {
description?: string;
hookOptions?: SGHookOptionsMap;
input?: SGInputFieldConfigMap;
output: SGOutputFieldConfig<T>;
resolve?: SGFieldResolve<T>;
subscribe: (args: {
[key: string]: any;
}, context: SGResolveContext, info: GraphQLResolveInfo, sgContext: SGContext) => AsyncGenerator<T>;
};
export declare type SGSubscriptionConfigMap = {
[key: string]: SGSubscriptionConfig;
};
export declare type SGMutationConfig<T = any> = {

@@ -265,2 +279,5 @@ description?: string;

} | {
type: 'subscription';
targetConfig: SGSubscriptionConfig;
} | {
type: 'mutation';

@@ -312,2 +329,3 @@ targetConfig: SGMutationConfig;

mutations?: SGMutationConfigMap;
subscriptions?: SGSubscriptionConfigMap;
};

@@ -314,0 +332,0 @@ export interface SGCacheManager {

@@ -30,4 +30,4 @@ "use strict";

const self = this;
const relateModelNames = [self.model.name, ...(0, getIncludeModeNames_1.default)(options)];
return `${self.prefix}|${method}|${relateModelNames.join('|')}|${(0, getFindOptionsKey_1.default)(self.model, options)}`;
const relateModelNames = [self.model.name, ...getIncludeModeNames_1.default(options)];
return `${self.prefix}|${method}|${relateModelNames.join('|')}|${getFindOptionsKey_1.default(self.model, options)}`;
}

@@ -46,3 +46,3 @@ isCacheValid(options) {

self.model.name,
...(0, getIncludeModeNames_1.default)(options)
...getIncludeModeNames_1.default(options)
];

@@ -63,3 +63,3 @@ return (transaction.clearCaches.find((cache) => relateModelNames.indexOf(cache.model.name) !== -1) == null);

if (cacheValue !== undefined) {
return cacheValue.map((value) => (0, dataToInstance_1.default)(value, self.model, (options === null || options === void 0 ? void 0 : options.include) || []));
return cacheValue.map((value) => dataToInstance_1.default(value, self.model, (options === null || options === void 0 ? void 0 : options.include) || []));
}

@@ -72,3 +72,3 @@ else {

if ((yield self.cacheManger.get(lockKey)) === lockValue) {
yield self.cacheManger.set(cacheKey, result.map((r) => (0, instanceToData_1.default)(r)), self.expire);
yield self.cacheManger.set(cacheKey, result.map((r) => instanceToData_1.default(r)), self.expire);
}

@@ -88,3 +88,3 @@ return result;

if (cacheValue !== undefined) {
return (0, dataToInstance_1.default)(cacheValue, self.model, options ? options.include : []);
return dataToInstance_1.default(cacheValue, self.model, options ? options.include : []);
}

@@ -97,3 +97,3 @@ else {

if ((yield self.cacheManger.get(lockKey)) === lockValue) {
yield self.cacheManger.set(cacheKey, (0, instanceToData_1.default)(result), self.expire);
yield self.cacheManger.set(cacheKey, instanceToData_1.default(result), self.expire);
}

@@ -100,0 +100,0 @@ return result;

import { SGPluginConfig } from '../index';
declare const _default: SGPluginConfig<import("../index").SGPluginOptions>;
declare const _default: SGPluginConfig<import("..").SGPluginOptions>;
export default _default;
import { SGPluginConfig } from '../index';
declare const _default: SGPluginConfig<import("../index").SGPluginOptions>;
declare const _default: SGPluginConfig<import("..").SGPluginOptions>;
export default _default;

@@ -5,4 +5,4 @@ import { GraphQLFieldConfigMap } from 'graphql';

declare const toGraphQLFieldConfigMap: (name: string, postfix: string, fields: {
[id: string]: SGOutputFieldConfig<any, any, any, any>;
[id: string]: import("..").SGFieldTypeDefinition<import("..").SGOutputFieldTypeMetadata<any, any>, import("..").SGOutputFieldTypeMetadata<any, any>>;
}, context: Context) => GraphQLFieldConfigMap<any, any>;
export default toGraphQLFieldConfigMap;

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

type: typeConfig.outputType,
args: (0, toGraphQLInputFieldConfigMap_1.default)(toTypeName(fieldName, fieldPath), typeConfig.additionalInput || {}, context)
args: toGraphQLInputFieldConfigMap_1.default(toTypeName(fieldName, fieldPath), typeConfig.additionalInput || {}, context)
};

@@ -96,3 +96,3 @@ const outputResolve = typeConfig.outputResolve;

if ((_k = (_j = field.metadata) === null || _j === void 0 ? void 0 : _j.graphql) === null || _k === void 0 ? void 0 : _k.input) {
config.args = Object.assign(Object.assign({}, config.args), (0, toGraphQLInputFieldConfigMap_1.default)(toTypeName(name, path), (_m = (_l = field.metadata) === null || _l === void 0 ? void 0 : _l.graphql) === null || _m === void 0 ? void 0 : _m.input, context));
config.args = Object.assign(Object.assign({}, config.args), toGraphQLInputFieldConfigMap_1.default(toTypeName(name, path), (_m = (_l = field.metadata) === null || _l === void 0 ? void 0 : _l.graphql) === null || _m === void 0 ? void 0 : _m.input, context));
}

@@ -99,0 +99,0 @@ return config;

import { GraphQLInputFieldConfigMap } from 'graphql';
import { SGInputFieldConfig, SGTypeContext } from '..';
declare const toGraphQLInputFieldConfigMap: (name: string, fields: {
[id: string]: SGInputFieldConfig;
[id: string]: import("..").SGFieldTypeDefinition<import("..").SGInputFieldTypeMetadata, import("..").SGInputFieldTypeMetadata>;
}, context: SGTypeContext) => GraphQLInputFieldConfigMap;
export default toGraphQLInputFieldConfigMap;

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

return makeNonNull({
type: (0, unionInputType_1.default)({
type: unionInputType_1.default({
name: StringHelper_1.default.toInitialUpperCase(toTypeName(name, path)) + 'Input',

@@ -88,0 +88,0 @@ inputValueTypes: lodash_1.default.mapValues(field.mapping, (options, key) => {

{
"name": "simple-graphql",
"version": "5.1.6",
"version": "5.2.0",
"description": "The simple way to generates GraphQL schemas and Sequelize models from your models definition.",

@@ -39,3 +39,3 @@ "main": "dist/index.js",

"lru_map": "^0.3.3",
"sequelize": "^6.5.0"
"sequelize": "6.5.0"
},

@@ -49,2 +49,3 @@ "devDependencies": {

"graphql-relay": "^0.9.0",
"graphql-ws": "^5.11.2",
"jest": "^26.6.3",

@@ -57,3 +58,4 @@ "mysql2": "^1.7.0",

"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"typescript": "4.1.3",
"ws": "^8.11.0"
},

@@ -60,0 +62,0 @@ "pre-commit": [

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

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

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

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

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