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 0.4.2 to 1.0.0

flow-typed/npm/babel-eslint_vx.x.x.js

8

flow-typed/npm/babel-plugin-transform-flow-strip-types_vx.x.x.js

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

// flow-typed signature: e855abd2ed4bfd505cdf68b6704f2d77
// flow-typed version: <<STUB>>/babel-plugin-transform-flow-strip-types_v^6.22.0/flow_v0.42.0
// flow-typed signature: 76f3437705b4bba680c5b5e99d9f706e
// flow-typed version: <<STUB>>/babel-plugin-transform-flow-strip-types_v^6.22.0/flow_v0.51.1

@@ -11,4 +11,4 @@ /**

*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed

@@ -15,0 +15,0 @@ */

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

// flow-typed signature: 81fc1253b811ace77143aa0b251c7e62
// flow-typed version: <<STUB>>/babel-polyfill_v^6.23.0/flow_v0.42.0
// flow-typed signature: 4cf9ef8f5e1f8f33b70a9572fb5155a7
// flow-typed version: <<STUB>>/babel-polyfill_v^6.23.0/flow_v0.51.1

@@ -11,4 +11,4 @@ /**

*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed

@@ -15,0 +15,0 @@ */

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

// flow-typed signature: 8d41be63b856d7552190adfd379e11c5
// flow-typed version: <<STUB>>/babel-preset-es2015_v^6.24.0/flow_v0.42.0
// flow-typed signature: 4885796843ffa6c0999e3ce8901abdcb
// flow-typed version: <<STUB>>/babel-preset-es2015_v^6.24.0/flow_v0.51.1

@@ -11,4 +11,4 @@ /**

*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed

@@ -15,0 +15,0 @@ */

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

// flow-typed signature: c22641de0cb3a9d9ee8756b7e95e2162
// flow-typed version: <<STUB>>/babel-preset-stage-3_v^6.22.0/flow_v0.42.0
// flow-typed signature: ad13edc9fb2b1621ecbb77f78e0ef235
// flow-typed version: <<STUB>>/babel-preset-stage-3_v^6.22.0/flow_v0.51.1

@@ -11,4 +11,4 @@ /**

*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed

@@ -15,0 +15,0 @@ */

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

// flow-typed signature: 0c44360c73d24505c966460972a30d4e
// flow-typed version: 73bd90ad54/lodash_v4.x.x/flow_>=v0.38.x
// flow-typed signature: 965815c926d58b631e3746ecfe0bc204
// flow-typed version: 0953311d72/lodash_v4.x.x/flow_>=v0.47.x

@@ -182,5 +182,5 @@ declare module 'lodash' {

filter<A, T: {[id: string]: A}>(object: T, predicate?: OPredicate<A, T>): Array<A>;
find<T>(array: ?Array<T>, predicate?: Predicate<T>): T;
find<V, A, T: {[id: string]: A}>(object: T, predicate?: OPredicate<A, T>): V;
findLast<T>(array: ?Array<T>, predicate?: Predicate<T>): T;
find<T>(array: ?Array<T>, predicate?: Predicate<T>, fromIndex?: number): T|void;
find<V, A, T: {[id: string]: A}>(object: T, predicate?: OPredicate<A, T>, fromIndex?: number): V;
findLast<T>(array: ?Array<T>, predicate?: Predicate<T>, fromIndex?: number): T|void;
findLast<V, A, T: {[id: string]: A}>(object: T, predicate?: OPredicate<A, T>): V;

@@ -205,3 +205,3 @@ flatMap<T, U>(array: ?Array<T>, iteratee?: FlatMapIteratee<T, U>): Array<U>;

keyBy<T, V>(array: ?Array<T>, iteratee?: ValueOnlyIteratee<T>): {[key: V]: ?T};
keyBy<V, A, T: {[id: string]: A}>(object: T, iteratee?: ValueOnlyIteratee<A>): {[key: V]: ?A};
keyBy<V, A, I, T: {[id: I]: A}>(object: T, iteratee?: ValueOnlyIteratee<A>): {[key: V]: ?A};
map<T, U>(array: ?Array<T>, iteratee?: MapIterator<T, U>): Array<U>;

@@ -308,3 +308,3 @@ map<V, T: Object, U>(object: ?T, iteratee?: OMapIterator<V, T, U>): Array<U>;

isString(value: string): true;
isString(value: number|Function|void|null|Object|Array<any>): false;
isString(value: number|bool|Function|void|null|Object|Array<any>): false;
isSymbol(value: any): bool;

@@ -389,3 +389,3 @@ isTypedArray(value: any): bool;

functionsIn(object?: ?Object): Array<string>;
get(object?: ?Object, path?: ?Array<string>|string, defaultValue?: any): any;
get(object?: ?Object|?Array<any>, path?: ?Array<string>|string, defaultValue?: any): any;
has(object?: ?Object, path?: ?Array<string>|string): bool;

@@ -486,3 +486,3 @@ hasIn(object?: ?Object, path?: ?Array<string>|string): bool;

noConflict(): Lodash;
noop(): void;
noop(...args: Array<mixed>): void;
nthArg(n?: number): Function;

@@ -489,0 +489,0 @@ over(...iteratees: Array<Function>): Function;

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

// flow-typed signature: d44388f51527a2bb754e547cfd25ae85
// flow-typed version: 0f1bb24013/moment_v2.x.x/flow_>=v0.34.x
// flow-typed signature: b066790a0280dbd8ea71ea2a212c78ef
// flow-typed version: b43dff3e0e/moment_v2.x.x/flow_>=v0.28.x

@@ -58,2 +58,4 @@ type moment$MomentOptions = {

type moment$Inclusivity = '()' | '[)' | '()' | '(]' | '[]'
declare class moment$LocaleData {

@@ -107,3 +109,8 @@ months(moment: moment$Moment): string;

static (string?: string, format?: string|Array<string>, locale?: string, strict?: bool): moment$Moment;
static (initDate: ?Object|number|Date|Array<number>|moment$Moment|string): moment$Moment;
static (
initDate: ?Object|number|Date|Array<number>|moment$Moment|string,
validFormats?: ?Array<string>|string,
locale?: ?boolean|string,
strict?: ?boolean|string
): moment$Moment;
static unix(seconds: number): moment$Moment;

@@ -186,3 +193,3 @@ static utc(): moment$Moment;

utc(): this;
utcOffset(offset: number|string): this;
utcOffset(offset: number|string, keepLocalTime?: boolean, keepMinutes?: boolean): this;
utcOffset(): number;

@@ -204,8 +211,8 @@ format(format?: string): string;

toObject(): moment$MomentObject;
isBefore(date?: moment$Moment|string|number|Date|Array<number>): bool;
isSame(date?: moment$Moment|string|number|Date|Array<number>): bool;
isAfter(date?: moment$Moment|string|number|Date|Array<number>): bool;
isSameOrBefore(date?: moment$Moment|string|number|Date|Array<number>): bool;
isSameOrAfter(date?: moment$Moment|string|number|Date|Array<number>): bool;
isBetween(date: moment$Moment|string|number|Date|Array<number>): bool;
isBetween(from: moment$Moment|string|number|Date|Array<number>, to: moment$Moment|string|number|Date|Array<number>, units?: string, inclusivity?: moment$Inclusivity): bool;
isBefore(date?: moment$Moment|string|number|Date|Array<number>, units?: ?string): bool;
isSame(date?: moment$Moment|string|number|Date|Array<number>, units?: ?string): bool;
isAfter(date?: moment$Moment|string|number|Date|Array<number>, units?: ?string): bool;
isSameOrBefore(date?: moment$Moment|string|number|Date|Array<number>, units?: ?string): bool;
isSameOrAfter(date?: moment$Moment|string|number|Date|Array<number>, units?: ?string): bool;
isDST(): bool;

@@ -217,4 +224,4 @@ isDSTShifted(): bool;

static isDate(obj: any): bool;
static locale(locale: string, localeData?: Object): string;
static updateLocale(locale: string, localeData?: ?Object): void;
static locale(locale?: string, localeData?: Object): string;
static locale(locales: Array<string>): string;

@@ -221,0 +228,0 @@ locale(locale: string, customization?: Object|null): moment$Moment;

@@ -29,3 +29,3 @@ declare class DataType {

static cls:any;
static useCLS:any;
static col:any;

@@ -140,2 +140,3 @@ static fn:any;

showAllSchemas:(any) => Promise<any>;
models:{[string]:Sequelize.Model}
}

@@ -142,0 +143,0 @@

@@ -27,18 +27,6 @@ 'use strict';

var _query = require('./query');
var _Schema = require('./schema/Schema');
var _query2 = _interopRequireDefault(_query);
var _Schema2 = _interopRequireDefault(_Schema);
var _mutation = require('./mutation');
var _mutation2 = _interopRequireDefault(_mutation);
var _Model = require('./Model');
var _Model2 = _interopRequireDefault(_Model);
var _ModelRef = require('./ModelRef');
var _ModelRef2 = _interopRequireDefault(_ModelRef);
var _StringHelper = require('./utils/StringHelper');

@@ -52,2 +40,6 @@

var _SequelizeContext = require('./sequelize/SequelizeContext');
var _SequelizeContext2 = _interopRequireDefault(_SequelizeContext);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -65,7 +57,7 @@

this.sequelize = sequelize;
this.dbContext = new _SequelizeContext2.default(sequelize);
this.options = _extends({}, options);
this.dbModels = {};
this.models = {};
this.schemas = {};
this.graphQLObjectTypes = {};

@@ -78,3 +70,9 @@ this.queries = {};

var self = this;
this.nodeInterface = relay.nodeDefinitions(null, function (obj) {
this.nodeInterface = relay.nodeDefinitions(function (globalId) {
var _relay$fromGlobalId = relay.fromGlobalId(globalId),
type = _relay$fromGlobalId.type,
id = _relay$fromGlobalId.id;
console.log('Warning-------------------- node id Fetcher not implement' + type + ' ' + id);
}, function (obj) {
var type = obj._type;

@@ -86,12 +84,16 @@ return self.graphQLObjectTypes[type];

_createClass(Context, [{
key: 'addModel',
value: function addModel(model) {
key: 'addSchema',
value: function addSchema(schema) {
var _this = this;
if (this.models[model.name]) {
throw new Error('Model ' + model.name + ' already define.');
if (this.schemas[schema.name]) {
throw new Error('Schema ' + schema.name + ' already define.');
}
this.models[model.name] = model;
this.schemas[schema.name] = schema;
model.fields({
this.dbContext.plugins().forEach(function (plugin) {
return plugin(schema, _this.options);
});
schema.fields({
createdAt: {

@@ -109,3 +111,3 @@ $type: Date,

_lodash2.default.forOwn(model.config.queries, function (value, key) {
_lodash2.default.forOwn(schema.config.queries, function (value, key) {
if (!value['name']) {

@@ -116,10 +118,4 @@ value['name'] = key;

});
if (model.config.options.singularQuery !== false) {
this.addQuery(_query2.default.singularQuery(model));
}
if (model.config.options.pluralQuery !== false) {
this.addQuery(_query2.default.pluralQuery(model));
}
_lodash2.default.forOwn(model.config.mutations, function (value, key) {
_lodash2.default.forOwn(schema.config.mutations, function (value, key) {
if (!value['name']) {

@@ -130,12 +126,3 @@ value['name'] = key;

});
if (model.config.options.addMutation !== false) {
this.addMutation(_mutation2.default.addMutation(model));
}
if (model.config.options.updateMutation !== false) {
this.addMutation(_mutation2.default.updateMutation(model));
}
if (model.config.options.deleteMutation !== false) {
this.addMutation(_mutation2.default.deleteMutation(model));
}
this.dbModel(model.name);
this.dbModel(schema.name);
}

@@ -161,5 +148,5 @@ }, {

value: function graphQLObjectType(name) {
var model = this.models[name];
var model = this.schemas[name];
if (!model) {
throw new Error('Model ' + name + ' not define.');
throw new Error('Schema ' + name + ' not define.');
}

@@ -199,8 +186,6 @@ var typeName = model.name;

Object.assign(obj, _query2.default.hasManyQueryFields(model));
Object.assign(obj, _query2.default.hasOneQueryFields(model));
this.graphQLObjectTypes[typeName] = _transformer2.default.toGraphQLFieldConfig(typeName, '', obj, this, interfaces).type;
if (this.graphQLObjectTypes[typeName] instanceof graphql.GraphQLObjectType) {
this.graphQLObjectTypes[typeName].description = model.config.options.description;
var objectType = _transformer2.default.toGraphQLFieldConfig(typeName, '', obj, this, interfaces).type;
if (objectType instanceof graphql.GraphQLObjectType) {
objectType.description = model.config.options.description;
this.graphQLObjectTypes[typeName] = objectType;
}

@@ -213,5 +198,5 @@ }

value: function dbModel(name) {
var model = this.models[name];
var model = this.schemas[name];
if (!model) {
throw new Error('Model ' + name + ' not define.');
throw new Error('Schema ' + name + ' not define.');
}

@@ -221,5 +206,5 @@ var typeName = model.name;

if (!this.dbModels[typeName]) {
this.dbModels[typeName] = _transformer2.default.toSequelizeModel(this.sequelize, model);
this.dbModels[typeName] = this.dbContext.define(model);
Object.assign(this.dbModels[typeName], model.config.statics);
Object.assign(this.dbModels[typeName].Instance.prototype, model.config.methods);
Object.assign(this.dbModels[typeName].prototype, model.config.methods);
}

@@ -236,10 +221,7 @@ return this.dbModels[typeName];

var dbModels = function dbModels() {
return _lodash2.default.mapValues(_this2.models, function (model) {
return self.dbModel(model.name);
return _lodash2.default.mapValues(_this2.schemas, function (schema) {
return self.dbModel(schema.name);
});
};
var invoker = function invoker(schema, context, rootValue, requestString, variableValues) {
return graphql['graphql'](schema, requestString, rootValue, context, variableValues);
};
var hookFun = function hookFun(action, invokeInfo, next) {

@@ -271,3 +253,3 @@ return next();

}, function () {
return config.resolve(args, context, info, dbModels(), invoker.bind(null, info.schema, context, info.rootValue));
return config.resolve(args, context, info, dbModels());
});

@@ -284,3 +266,3 @@ };

var dbModels = function dbModels() {
return _lodash2.default.mapValues(_this3.models, function (model) {
return _lodash2.default.mapValues(_this3.schemas, function (model) {
return self.dbModel(model.name);

@@ -290,5 +272,2 @@ });

var invoker = function invoker(schema, context, rootValue, requestString, variableValues) {
return graphql['graphql'](schema, requestString, rootValue, context, variableValues);
};
var hookFun = function hookFun(action, invokeInfo, next) {

@@ -319,3 +298,3 @@ return next();

}, function () {
return config.resolve(source, args, context, info, dbModels(), invoker.bind(null, info.schema, context, info.rootValue));
return config.resolve(source, args, context, info, dbModels());
});

@@ -332,10 +311,7 @@ };

var dbModels = function dbModels() {
return _lodash2.default.mapValues(_this4.models, function (model) {
return self.dbModel(model.name);
return _lodash2.default.mapValues(_this4.schemas, function (schema) {
return self.dbModel(schema.name);
});
};
var invoker = function invoker(schema, context, rootValue, requestString, variableValues) {
return graphql['graphql'](schema, requestString, rootValue, context, variableValues);
};
var hookFun = function hookFun(action, invokeInfo, next) {

@@ -365,3 +341,3 @@ return next();

}, function () {
return config.mutateAndGetPayload(args, context, info, dbModels(), invoker.bind(null, info.schema, context, info.rootValue));
return config.mutateAndGetPayload(args, context, info, dbModels());
});

@@ -372,7 +348,7 @@ };

key: 'connectionDefinition',
value: function connectionDefinition(ref) {
if (!this.connectionDefinitions[ref.name]) {
this.connectionDefinitions[ref.name] = relay.connectionDefinitions({
name: _StringHelper2.default.toInitialUpperCase(ref.name),
nodeType: this.graphQLObjectType(ref.name),
value: function connectionDefinition(schemaName) {
if (!this.connectionDefinitions[schemaName]) {
this.connectionDefinitions[schemaName] = relay.connectionDefinitions({
name: _StringHelper2.default.toInitialUpperCase(schemaName),
nodeType: this.graphQLObjectType(schemaName),
connectionFields: {

@@ -385,13 +361,13 @@ count: {

}
return this.connectionDefinitions[ref.name];
return this.connectionDefinitions[schemaName];
}
}, {
key: 'connectionType',
value: function connectionType(ref) {
return this.connectionDefinition(ref).connectionType;
value: function connectionType(schemaName) {
return this.connectionDefinition(schemaName).connectionType;
}
}, {
key: 'edgeType',
value: function edgeType(ref) {
return this.connectionDefinition(ref).edgeType;
value: function edgeType(schemaName) {
return this.connectionDefinition(schemaName).edgeType;
}

@@ -402,14 +378,27 @@ }, {

var self = this;
_lodash2.default.forOwn(self.models, function (model, key) {
model.config.associations.hasOne.forEach(function (config) {
self.dbModel(model.name).hasOne(self.dbModel(config.target), config.options);
_lodash2.default.forOwn(self.schemas, function (schema, key) {
_lodash2.default.forOwn(schema.config.associations.hasOne, function (config, key) {
self.dbModel(schema.name).hasOne(self.dbModel(config.target), _extends({}, config.options, {
as: key,
foreignKey: config.foreignField + 'Id'
}));
});
model.config.associations.belongsTo.forEach(function (config) {
self.dbModel(model.name).belongsTo(self.dbModel(config.target), config.options);
_lodash2.default.forOwn(schema.config.associations.belongsTo, function (config, key) {
self.dbModel(schema.name).belongsTo(self.dbModel(config.target), _extends({}, config.options, {
as: key,
foreignKey: config.foreignField + 'Id'
}));
});
model.config.associations.hasMany.forEach(function (config) {
self.dbModel(model.name).hasMany(self.dbModel(config.target), config.options);
_lodash2.default.forOwn(schema.config.associations.hasMany, function (config, key) {
self.dbModel(schema.name).hasMany(self.dbModel(config.target), _extends({}, config.options, {
as: key,
foreignKey: config.foreignField + 'Id'
}));
});
model.config.associations.belongsToMany.forEach(function (config) {
self.dbModel(model.name).belongsToMany(self.dbModel(config.target), config.options);
_lodash2.default.forOwn(schema.config.associations.belongsToMany, function (config, key) {
self.dbModel(schema.name).belongsToMany(self.dbModel(config.target), _extends({}, config.options, {
as: key,
foreignKey: config.foreignField + 'Id'
}));
});

@@ -416,0 +405,0 @@ });

@@ -11,10 +11,2 @@ 'use strict';

var _Connection = require('./Connection');
var _Connection2 = _interopRequireDefault(_Connection);
var _ModelRef = require('./ModelRef');
var _ModelRef2 = _interopRequireDefault(_ModelRef);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _sequelize = require('sequelize');

@@ -24,5 +26,5 @@

var _Model = require('./Model');
var _Schema = require('./schema/Schema');
var _Model2 = _interopRequireDefault(_Model);
var _Schema2 = _interopRequireDefault(_Schema);

@@ -41,10 +43,2 @@ var _type = require('./type');

var _Connection = require('./Connection');
var _Connection2 = _interopRequireDefault(_Connection);
var _ModelRef = require('./ModelRef');
var _ModelRef2 = _interopRequireDefault(_ModelRef);
var _transformer = require('./transformer');

@@ -60,117 +54,2 @@

/**
* Usage:
*
* @example
*
* 1.Define the model
*
* //
* import SG from 'simple-graphql'
*
* const TodoType = SG.modelRef('Todo')
*
* export default SG.model('Todo').fields({
* title: {
* $type: String,
* required: true
* },
* description: String,
* completed: {
* $type: Boolean,
* required: true
* },
* dueAt: Date
* }).queries({
* dueTodos: {
* description: "Find all due todos",
* $type: [TodoType],
* args: {
* dueBefore: {
* $type: Date,
* required: true
* }
* },
* resolve: async function ({ dueBefore}, context, info, {Todo}) {
* return Todo.find({
* where: {
* completed: false,
* dueAt: {
* $lt: dueBefore
* }
* }
* })
* }
* }
* }).mutations({
* cpmpletedTodo: {
* description: "Mark the todo task completed.",
* inputFields: {
* todoId: {
* $type: TodoType,
* required: true
* }
* },
* outputFields: {
* changedTodo: TodoType
* },
* mutateAndGetPayload: async function ({todoId}, context, info, {Todo}) {
* const todo = await Todo.findOne({where: {id: todoId}})
* if (!todo) {
* throw new Error("Todo entity not found.")
* }
* if (!todo.completed) {
* todo.completed = true
* await todo.save()
* }
* return {changedTodo: todo}
* }
* }
* })
*
* 2. Config the Sequelize database connection.
*
* import Sequelize from 'sequelize'
* const sequelize = new Sequelize('test1', 'postgres', 'Password', {
* host: 'localhost',
* port: 5432,
* dialect: 'postgres',
*
* pool: {
* max: 5,
* min: 0,
* idle: 10000
* }
* })
* export default sequelize
*
* 3. Generate the GraphQL Schema
*
* import SG from 'simple-graphql'
*
* //import Todo model and sequlize config ...
*
* const schema = GS.build(sequelize, [Todo], {})
*
* //After bulid, all sequelize models have defined, then call sequelize.sync will automatic create the schema in database.
* sequelize.sync({
* force: false,
* logging: console.log
* }).then(() => console.log('Init DB Done'), (err) => console.log('Init DB Fail', err))
*
* export default
*
* 4. Start the GraphQL server
*
* const express = require('express');
* const graphqlHTTP = require('express-graphql');
*
* const app = express();
*
* app.use('/graphql', graphqlHTTP({
* schema: MyGraphQLSchema,
* graphiql: true
* }));
* app.listen(4000);
*/
var SimpleGraphQL = {

@@ -193,11 +72,6 @@

/**
* Get the Relay Connction helper
*/
Connection: _Connection2.default,
Schema: _Schema2.default,
Model: _Model2.default,
/**
* Define a Model
* Define a Schema
*

@@ -207,20 +81,11 @@ * @param name

*/
model: function model(name) {
schema: function schema(name) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new _Model2.default(name, options);
return new _Schema2.default(name, options);
},
/**
* @public
* Create a model reference, which can be using on the field type definition.
* @param name
*/
modelRef: function modelRef(name) {
return new _ModelRef2.default(name);
},
/**
* Build the GraphQL Schema
*/
build: function build(sequelize, models) {
build: function build(sequelize, schemas) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -230,5 +95,5 @@

// 添加Model
models.forEach(function (model) {
context.addModel(model);
// 添加Schema
schemas.forEach(function (schema) {
context.addSchema(schema);
});

@@ -241,9 +106,10 @@

_lodash2.default.forOwn(context.queries, function (value, key) {
var fieldConfig = _transformer2.default.toGraphQLFieldConfig(key, 'Payload', value.$type, context);
finalQueries[key] = {
type: _transformer2.default.toGraphQLFieldConfig(key, 'Payload', value.$type, context).type,
type: fieldConfig.type,
resolve: context.wrapQueryResolve(value),
description: value.description
};
if (value.args) {
finalQueries[key].args = _transformer2.default.toGraphQLInputFieldMap(_StringHelper2.default.toInitialUpperCase(key), value.args);
if (value.args || fieldConfig.args) {
finalQueries[key].args = _transformer2.default.toGraphQLInputFieldMap(_StringHelper2.default.toInitialUpperCase(key), _extends({}, fieldConfig.args, value.args));
}

@@ -250,0 +116,0 @@ });

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

@@ -9,2 +9,3 @@ "main": "lib/index.js",

"test": "jest",
"sequelize-demo": "babel-node src/sequelize/__tests__/server.js",
"flow": "flow; test $? -eq 0 -o $? -eq 2",

@@ -40,10 +41,7 @@ "build": "rm -rf lib && babel src --optional runtime --out-dir lib/ && cp package.json lib/ && npm run build-dot-flow",

"moment": "^2.18.1",
"sequelize": "^3.30.2"
"sequelize": "^4.4.2"
},
"peerDependencies": {
"graphql": "^0.9.1",
"graphql-relay": "^0.5.1"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-plugin-transform-flow-strip-types": "^6.22.0",

@@ -54,6 +52,8 @@ "babel-polyfill": "^6.23.0",

"eslint-plugin-flowtype": "^2.32.1",
"flow-bin": "^0.42.0",
"graphql": "^0.9.1",
"graphql-relay": "0.5.1",
"jest": "^19.0.2",
"express": "^4.15.4",
"express-graphql": "^0.6.7",
"flow-bin": "^0.51.1",
"graphql": "^0.10.5",
"graphql-relay": "^0.5.2",
"jest": "^20.0.4",
"pre-commit": "^1.2.2",

@@ -78,3 +78,10 @@ "sqlite3": "^3.1.8",

"format"
]
],
"jest": {
"verbose": true,
"setupTestFrameworkScriptFile": "./src/sequelize/__tests__/setup.js",
"testMatch": [
"<rootDir>/src/**/__tests__/**/*-test.js?(x)"
]
}
}

@@ -19,6 +19,2 @@ 'use strict';

var _toSequelizeModel = require('./toSequelizeModel');
var _toSequelizeModel2 = _interopRequireDefault(_toSequelizeModel);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -29,4 +25,3 @@

toGraphQLFieldConfig: _toGraphQLFieldConfig2.default,
toSequelizeModel: _toSequelizeModel2.default,
mutationWithClientMutationId: _mutationWithClientMutationId2.default
};

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _lodash = require('lodash');

@@ -28,10 +30,2 @@

var _Connection = require('../Connection');
var _Connection2 = _interopRequireDefault(_Connection);
var _ModelRef = require('../ModelRef');
var _ModelRef2 = _interopRequireDefault(_ModelRef);
var _toGraphQLInputFieldMap = require('./toGraphQLInputFieldMap');

@@ -112,74 +106,89 @@

if (fieldType instanceof _ModelRef2.default) {
return {
type: context.graphQLObjectType(fieldType.name),
resolve: context.wrapFieldResolve({
name: name.split('.').slice(-1)[0],
path: name,
$type: context.graphQLObjectType(fieldType.name),
resolve: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(root, args, context, info, models) {
var fieldName;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
fieldName = name.split('.').slice(-1)[0];
if (typeof fieldType === 'string') {
if (fieldType.endsWith('Edge')) {
return {
type: context.edgeType(fieldType.substr(0, fieldType.length - 'Edge'.length))
};
} else if (fieldType.endsWith('Connection')) {
return {
// Add Relay Connection Args
args: {
after: {
$type: String,
description: '返回的记录应该在cursor:after之后'
},
first: {
$type: Number,
description: '指定最多返回记录的数量'
},
before: {
$type: String
},
last: {
$type: Number
}
},
type: context.connectionType(fieldType.substr(0, fieldType.length - 'Connection'.length))
};
} else {
return {
type: context.graphQLObjectType(fieldType),
resolve: context.wrapFieldResolve({
name: name.split('.').slice(-1)[0],
path: name,
$type: context.graphQLObjectType(fieldType),
resolve: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(root, args, context, info, models) {
var fieldName;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
fieldName = name.split('.').slice(-1)[0];
if (!_lodash2.default.isFunction(root['get' + _StringHelper2.default.toInitialUpperCase(fieldName)])) {
_context2.next = 7;
break;
}
if (!_lodash2.default.isFunction(root['get' + _StringHelper2.default.toInitialUpperCase(fieldName)])) {
_context2.next = 7;
break;
}
if (!(root[fieldName] != null && root[fieldName].id != null)) {
_context2.next = 6;
break;
}
if (!(root[fieldName] != null && root[fieldName].id != null)) {
_context2.next = 6;
break;
}
return _context2.abrupt('return', root[fieldName]);
return _context2.abrupt('return', root[fieldName]);
case 6:
return _context2.abrupt('return', root['get' + _StringHelper2.default.toInitialUpperCase(fieldName)]());
case 6:
return _context2.abrupt('return', root['get' + _StringHelper2.default.toInitialUpperCase(fieldName)]());
case 7:
if (!(root && root[fieldName] && (typeof root[fieldName] === 'number' || typeof root[fieldName] === 'string'))) {
_context2.next = 9;
break;
}
case 7:
if (!(root && root[fieldName] && (typeof root[fieldName] === 'number' || typeof root[fieldName] === 'string'))) {
_context2.next = 9;
break;
}
return _context2.abrupt('return', models[fieldType.name].findOne({ where: { id: root[fieldName] } }));
return _context2.abrupt('return', models[fieldType].findOne({ where: { id: root[fieldName] } }));
case 9:
return _context2.abrupt('return', root[fieldName]);
case 9:
return _context2.abrupt('return', root[fieldName]);
case 10:
case 'end':
return _context2.stop();
case 10:
case 'end':
return _context2.stop();
}
}
}
}, _callee2, this);
}));
}, _callee2, this);
}));
function resolve(_x3, _x4, _x5, _x6, _x7) {
return _ref2.apply(this, arguments);
}
function resolve(_x3, _x4, _x5, _x6, _x7) {
return _ref2.apply(this, arguments);
}
return resolve;
}()
})
};
return resolve;
}()
})
};
}
}
if (fieldType instanceof _Connection2.default.ConnectionType) {
return {
type: context.connectionType(fieldType.nodeType)
};
}
if (fieldType instanceof _Connection2.default.EdgeType) {
return {
type: context.edgeType(fieldType.nodeType)
};
}
if (fieldType instanceof Object) {

@@ -209,4 +218,4 @@ if (fieldType['$type']) {

}
if (fieldType['args']) {
result['args'] = (0, _toGraphQLInputFieldMap2.default)(typeName(name), fieldType['args']);
if (fieldType.args || result.args) {
result.args = (0, _toGraphQLInputFieldMap2.default)(typeName(name), _extends({}, result.args, fieldType.args));
}

@@ -213,0 +222,0 @@ result.description = fieldType['description'];

@@ -21,6 +21,2 @@ 'use strict';

var _ModelRef = require('../ModelRef');
var _ModelRef2 = _interopRequireDefault(_ModelRef);
var _StringHelper = require('../utils/StringHelper');

@@ -75,5 +71,10 @@

if (field instanceof _ModelRef2.default) {
if (typeof field === 'string') {
if (field.endsWith('Id')) {
return {
type: _type2.default.GraphQLScalarTypes.globalIdInputType(field.substr(0, field.length - 'Id'.length))
};
}
return {
type: _type2.default.GraphQLScalarTypes.globalIdInputType(field.name)
type: _type2.default.GraphQLScalarTypes.globalIdInputType(field)
};

@@ -80,0 +81,0 @@ }

@@ -30,3 +30,3 @@ 'use strict';

} else {
throw new Error('Incorrect globalId format: ', value);
throw new Error('Incorrect globalId format: ');
}

@@ -49,3 +49,3 @@ },

} else {
throw new Error('Incorrect globalId format: ', value);
throw new Error('Incorrect globalId format: ' + value);
}

@@ -52,0 +52,0 @@ }

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

@@ -9,2 +9,3 @@ "main": "lib/index.js",

"test": "jest",
"sequelize-demo": "babel-node src/sequelize/__tests__/server.js",
"flow": "flow; test $? -eq 0 -o $? -eq 2",

@@ -40,10 +41,7 @@ "build": "rm -rf lib && babel src --optional runtime --out-dir lib/ && cp package.json lib/ && npm run build-dot-flow",

"moment": "^2.18.1",
"sequelize": "^3.30.2"
"sequelize": "^4.4.2"
},
"peerDependencies": {
"graphql": "^0.9.1",
"graphql-relay": "^0.5.1"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-plugin-transform-flow-strip-types": "^6.22.0",

@@ -54,6 +52,8 @@ "babel-polyfill": "^6.23.0",

"eslint-plugin-flowtype": "^2.32.1",
"flow-bin": "^0.42.0",
"graphql": "^0.9.1",
"graphql-relay": "0.5.1",
"jest": "^19.0.2",
"express": "^4.15.4",
"express-graphql": "^0.6.7",
"flow-bin": "^0.51.1",
"graphql": "^0.10.5",
"graphql-relay": "^0.5.2",
"jest": "^20.0.4",
"pre-commit": "^1.2.2",

@@ -78,3 +78,10 @@ "sqlite3": "^3.1.8",

"format"
]
],
"jest": {
"verbose": true,
"setupTestFrameworkScriptFile": "./src/sequelize/__tests__/setup.js",
"testMatch": [
"<rootDir>/src/**/__tests__/**/*-test.js?(x)"
]
}
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc