src/schema/query/viewer.js
function getRelatedModelFields(User) {
    const fields = {};

    _.forEach(User.relations, (relation) => {

        const model = relation.modelTo;

        fields[_.lowerFirst(relation.name)] = {
            args: Object.assign({
                where: {
                    type: getType('JSON')
                },
                order: {
                    type: getType('JSON')
                },
            }, connectionArgs),
            type: getConnection(model.modelName),
            resolve: (obj, args, context) => {

                if (!context.req.accessToken) return null;

                return findUserFromAccessToken(context.req.accessToken, User)
                    .then(user => connectionFromPromisedArray(findAllRelated(User, user, relation.name, args, context), args, model));
            }
        };
    });

    return fields;
}
function getRelatedModelFields(User) {
    const fields = {};

    _.forEach(User.relations, (relation) => {

        const model = relation.modelTo;

        fields[_.lowerFirst(relation.name)] = {
            args: Object.assign({
                where: {
                    type: getType('JSON')
                },
                order: {
                    type: getType('JSON')
                },
            }, connectionArgs),
            type: getConnection(model.modelName),
            resolve: (obj, args, context) => {

                if (!context.req.accessToken) return null;

                return findUserFromAccessToken(context.req.accessToken, User)
                    .then(user => connectionFromPromisedArray(findAllRelated(User, user, relation.name, args, context), args, model));
            }
        };
    });

    return fields;
}
function getRelatedModelFields ( User ) { const fields = { } ; _ . forEach ( User . relations , ( relation ) => { const model = relation . modelTo ; fields [ _ . lowerFirst ( relation . name ) ] = { args : Object . assign ( { where : { type : getType ( 'JSON' ) } , order : { type : getType ( 'JSON' ) } , } , connectionArgs ) , type : getConnection ( model . modelName ) , resolve : ( obj , args , context ) => { if ( ! context . req . accessToken ) return null ; return findUserFromAccessToken ( context . req . accessToken , User ) . then ( user => connectionFromPromisedArray ( findAllRelated ( User , user , relation . name , args , context ) , args , model ) ) ; } } ; } ) ; return fields ; }
Adds fields of all relationed models
@param {*} models
Adds fields of all relationed models