lib/utils.js
function filterArgs(defaultArgs, opt) {
  opt = opt || {};
  const packValueToNonNull = value => (0, _assign2.default)({}, value, { type: new _graphql.GraphQLNonNull(value.type) });
  return (0, _entries2.default)(defaultArgs).filter(_ref => {
    var _ref2 = (0, _slicedToArray3.default)(_ref, 2);

    let arg = _ref2[0];
    let value = _ref2[1];

    if (opt.onlyId && arg !== 'id' && arg !== 'ids') return false;
    if (opt.id && (arg === 'id' || arg === 'ids')) return false;
    if (opt.plural && !value.onlyPlural && _pluralize2.default.plural(arg) === arg) return false;
    return true;
  }).map(_ref3 => {
    var _ref4 = (0, _slicedToArray3.default)(_ref3, 2);

    let arg = _ref4[0];
    let value = _ref4[1];

    let newValue = (0, _assign2.default)({}, value);
    if ((arg === 'id' || arg === 'ids') && opt.idRequired) newValue = packValueToNonNull(newValue);
    if (!opt.required && newValue.required && !newValue.context) newValue = packValueToNonNull(newValue);
    return [arg, newValue];
  }).reduce((args, _ref5) => {
    var _ref6 = (0, _slicedToArray3.default)(_ref5, 2);

    let arg = _ref6[0];
    let value = _ref6[1];

    return (0, _assign2.default)(args, { [arg]: value });
  }, {});
}
function filterArgs(defaultArgs, opt) {
  opt = opt || {};
  const packValueToNonNull = value => (0, _assign2.default)({}, value, { type: new _graphql.GraphQLNonNull(value.type) });
  return (0, _entries2.default)(defaultArgs).filter(_ref => {
    var _ref2 = (0, _slicedToArray3.default)(_ref, 2);

    let arg = _ref2[0];
    let value = _ref2[1];

    if (opt.onlyId && arg !== 'id' && arg !== 'ids') return false;
    if (opt.id && (arg === 'id' || arg === 'ids')) return false;
    if (opt.plural && !value.onlyPlural && _pluralize2.default.plural(arg) === arg) return false;
    return true;
  }).map(_ref3 => {
    var _ref4 = (0, _slicedToArray3.default)(_ref3, 2);

    let arg = _ref4[0];
    let value = _ref4[1];

    let newValue = (0, _assign2.default)({}, value);
    if ((arg === 'id' || arg === 'ids') && opt.idRequired) newValue = packValueToNonNull(newValue);
    if (!opt.required && newValue.required && !newValue.context) newValue = packValueToNonNull(newValue);
    return [arg, newValue];
  }).reduce((args, _ref5) => {
    var _ref6 = (0, _slicedToArray3.default)(_ref5, 2);

    let arg = _ref6[0];
    let value = _ref6[1];

    return (0, _assign2.default)(args, { [arg]: value });
  }, {});
}
function filterArgs ( defaultArgs , opt ) { opt = opt || { } ; const packValueToNonNull = value => ( 0 , _assign2 . default ) ( { } , value , { type : new _graphql . GraphQLNonNull ( value . type ) } ) ; return ( 0 , _entries2 . default ) ( defaultArgs ) . filter ( _ref => { var _ref2 = ( 0 , _slicedToArray3 . default ) ( _ref , 2 ) ; let arg = _ref2 [ 0 ] ; let value = _ref2 [ 1 ] ; if ( opt . onlyId && arg !== 'id' && arg !== 'ids' ) return false ; if ( opt . id && ( arg === 'id' || arg === 'ids' ) ) return false ; if ( opt . plural && ! value . onlyPlural && _pluralize2 . default . plural ( arg ) === arg ) return false ; return true ; } ) . map ( _ref3 => { var _ref4 = ( 0 , _slicedToArray3 . default ) ( _ref3 , 2 ) ; let arg = _ref4 [ 0 ] ; let value = _ref4 [ 1 ] ; let newValue = ( 0 , _assign2 . default ) ( { } , value ) ; if ( ( arg === 'id' || arg === 'ids' ) && opt . idRequired ) newValue = packValueToNonNull ( newValue ) ; if ( ! opt . required && newValue . required && ! newValue . context ) newValue = packValueToNonNull ( newValue ) ; return [ arg , newValue ] ; } ) . reduce ( ( args , _ref5 ) => { var _ref6 = ( 0 , _slicedToArray3 . default ) ( _ref5 , 2 ) ; let arg = _ref6 [ 0 ] ; let value = _ref6 [ 1 ] ; return ( 0 , _assign2 . default ) ( args , { [ arg ] : value } ) ; } , { } ) ; }
Filter arguments when doing CRUD
@params
- defaultArgs {Object} the result of buildArgs
- opt {Object {filter: {Bool}} options: id, plural, required, idRequired, onlyId
Filter arguments when doing CRUD