@truebill/graphql-sequelize
Advanced tools
Comparing version 8.3.1 to 8.3.2
@@ -19,2 +19,3 @@ 'use strict'; | ||
exports.createNodeInterface = createNodeInterface; | ||
exports.getInnerType = getInnerType; | ||
exports.nodeType = nodeType; | ||
@@ -122,4 +123,8 @@ exports.createConnection = createConnection; | ||
exports.sequelizeNodeInterface = createNodeInterface; | ||
function getInnerType(type) { | ||
return type instanceof _graphql.GraphQLNonNull ? type.ofType : type; | ||
} | ||
function nodeType(connectionType) { | ||
return connectionType._fields.edges.type.ofType._fields.node.type; | ||
return getInnerType(getInnerType(connectionType._fields.edges.type).ofType)._fields.node.type; | ||
} | ||
@@ -126,0 +131,0 @@ |
@@ -58,4 +58,4 @@ 'use strict'; | ||
model = isAssociation && target.target || isModel && target, | ||
type = info.returnType, | ||
list = options.list || type instanceof _graphql.GraphQLList || type instanceof _graphql.GraphQLNonNull && type.ofType instanceof _graphql.GraphQLList; | ||
type = (0, _relay.getInnerType)(info.returnType), | ||
list = options.list || type instanceof _graphql.GraphQLList; | ||
@@ -87,2 +87,9 @@ let targetAttributes = Object.keys(model.rawAttributes), | ||
function handleResult(result) { | ||
if (options.handleConnection && (0, _relay.isConnection)((0, _relay.getInnerType)(info.returnType))) { | ||
return (0, _relay.handleConnection)(result, args); | ||
} | ||
return result; | ||
} | ||
return _bluebird2.default.resolve(options.before(findOptions, args, context, info)).then(function (findOptions) { | ||
@@ -101,19 +108,9 @@ if (args.where && !_lodash2.default.isEmpty(info.variableValues)) { | ||
// The user did a manual include | ||
const result = source.get(association.as); | ||
if (options.handleConnection && (0, _relay.isConnection)(info.returnType)) { | ||
return (0, _relay.handleConnection)(result, args); | ||
} | ||
return result; | ||
return handleResult(source.get(association.as)); | ||
} else { | ||
return source[association.accessors.get](findOptions).then(function (result) { | ||
if (options.handleConnection && (0, _relay.isConnection)(info.returnType)) { | ||
return (0, _relay.handleConnection)(result, args); | ||
} | ||
return result; | ||
}); | ||
return source[association.accessors.get](findOptions).then(handleResult); | ||
} | ||
} | ||
return model[list ? 'findAll' : 'findOne'](findOptions); | ||
return model[list ? 'findAll' : 'findOne'](findOptions).then(handleResult); | ||
}).then(function (result) { | ||
@@ -120,0 +117,0 @@ return options.after(result, args, context, info); |
{ | ||
"name": "@truebill/graphql-sequelize", | ||
"version": "8.3.1", | ||
"version": "8.3.2", | ||
"description": "GraphQL & Relay for MySQL & Postgres via Sequelize", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
935
65705