src/types/generateTypeDefs.js
function mapRelation(rel, modelName, relName) {
    let acceptingParams = Object.assign({}, {
        filter: {
            generated: false,
            type: 'JSON'
        }
    }, connectionArgs);
    types[modelName].meta.fields[relName] = {
        generated: true,
        meta: {
            relation: true,
            connection: true,
            relationType: rel.type,
            isMany: isManyRelation(rel.type),
            embed: rel.embed,
            type: rel.modelTo.modelName,
            args: acceptingParams,
        },
        resolve: (obj, args, context, info) => {

            const ctxOptions = { accessToken: context.req.accessToken }
            const modelId = args && args.id;

            const method = rel.modelTo.sharedClass.findMethodByName('find');
            // TODO: ...
            return new Promise((resolve, reject) => { resolve(true) }).then(() => {
                let params = {};

                _.forEach(acceptingParams, (param, name) => {
                    if (typeof args[name] !== 'undefined' && Object.keys(args[name]).length > 0) {
                        _.merge(params, _.cloneDeep(args[name]));
                    }
                });

                if (isManyRelation(rel.type) === true) {
                    return connectionFromPromisedArray(findRelatedMany(rel, obj, params, context), args, rel.modelTo);
                } else {
                    return findRelatedOne(rel, obj, params, context);
                }

                // let wrap = promisify(model[method.name](...params, ctxOptions));

                // if (typeObj.list) {
                //     return connectionFromPromisedArray(wrap, args, model);
                // } else {
                //     return wrap;
                // }


            }).catch((err) => {
                throw err;
            });
        }
    };
}
function mapRelation(rel, modelName, relName) {
    let acceptingParams = Object.assign({}, {
        filter: {
            generated: false,
            type: 'JSON'
        }
    }, connectionArgs);
    types[modelName].meta.fields[relName] = {
        generated: true,
        meta: {
            relation: true,
            connection: true,
            relationType: rel.type,
            isMany: isManyRelation(rel.type),
            embed: rel.embed,
            type: rel.modelTo.modelName,
            args: acceptingParams,
        },
        resolve: (obj, args, context, info) => {

            const ctxOptions = { accessToken: context.req.accessToken }
            const modelId = args && args.id;

            const method = rel.modelTo.sharedClass.findMethodByName('find');
            // TODO: ...
            return new Promise((resolve, reject) => { resolve(true) }).then(() => {
                let params = {};

                _.forEach(acceptingParams, (param, name) => {
                    if (typeof args[name] !== 'undefined' && Object.keys(args[name]).length > 0) {
                        _.merge(params, _.cloneDeep(args[name]));
                    }
                });

                if (isManyRelation(rel.type) === true) {
                    return connectionFromPromisedArray(findRelatedMany(rel, obj, params, context), args, rel.modelTo);
                } else {
                    return findRelatedOne(rel, obj, params, context);
                }

                // let wrap = promisify(model[method.name](...params, ctxOptions));

                // if (typeObj.list) {
                //     return connectionFromPromisedArray(wrap, args, model);
                // } else {
                //     return wrap;
                // }


            }).catch((err) => {
                throw err;
            });
        }
    };
}
function mapRelation ( rel , modelName , relName ) { let acceptingParams = Object . assign ( { } , { filter : { generated : false , type : 'JSON' } } , connectionArgs ) ; types [ modelName ] . meta . fields [ relName ] = { generated : true , meta : { relation : true , connection : true , relationType : rel . type , isMany : isManyRelation ( rel . type ) , embed : rel . embed , type : rel . modelTo . modelName , args : acceptingParams , } , resolve : ( obj , args , context , info ) => { const ctxOptions = { accessToken : context . req . accessToken } const modelId = args && args . id ; const method = rel . modelTo . sharedClass . findMethodByName ( 'find' ) ; // TODO: ... return new Promise ( ( resolve , reject ) => { resolve ( true ) } ) . then ( ( ) => { let params = { } ; _ . forEach ( acceptingParams , ( param , name ) => { if ( typeof args [ name ] !== 'undefined' && Object . keys ( args [ name ] ) . length > 0 ) { _ . merge ( params , _ . cloneDeep ( args [ name ] ) ) ; } } ) ; if ( isManyRelation ( rel . type ) === true ) { return connectionFromPromisedArray ( findRelatedMany ( rel , obj , params , context ) , args , rel . modelTo ) ; } else { return findRelatedOne ( rel , obj , params , context ) ; } // let wrap = promisify(model[method.name](...params, ctxOptions)); // if (typeObj.list) { //     return connectionFromPromisedArray(wrap, args, model); // } else { //     return wrap; // } } ) . catch ( ( err ) => { throw err ; } ) ; } } ; }
Maps a relationship as a connection property to a given type
@param {*} rel
@param {*} modelName
@param {*} relName
Maps a relationship as a connection property to a given type