GithubHelp home page GithubHelp logo

Comments (14)

nodkz avatar nodkz commented on May 12, 2024

For removing fields from output:

UserTC.removeField('password');
UserTC.removeField(['password', ...otherFields]);

For removing some sub-fields from input argument:

UserTC.getResolver('updateOne').getArg('record').removeField('password');

Completely remove input argument:

UserTC.getResolver('updateMany'). removeArg(['skip', 'limit']);

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024

@nodkz is it possible to pick fields(removeOtherFields ?)?

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

Yep, removeOtherFields
May be better to rename this method. pickFields also not a good name.

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024
console.log(userTypeComposer.getResolver('findOne').getArg('filter').removeField);
console.log(userTypeComposer.getResolver('findOne').getArg('filter').removeArg);

undefined
undefined

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

Arguments has InputType and served by InputTypeComposer which has removeField method https://github.com/nodkz/graphql-compose/blob/master/src/inputTypeComposer.js

Try to debug via console.dir what you recieve via getArg

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024
const customizationOptions = {};
const userTypeComposer = composeWithMongoose(UserModel, customizationOptions);

userTypeComposer.removeOtherFields(['_id', 'name', 'email', 'status', 'role']);

const extendedResolver = userTypeComposer.getResolver('pagination').addFilterArg({
    name: 'search',
    type: 'String',
    description: 'Search by regExp',
    query: (rawQuery, value, resolveParams) => {
        if (value !== null && value !== undefined && value !== '') {
            Object.assign(rawQuery, {
                $or: [
                    { name: new RegExp(value, 'i') },
                    { email: new RegExp(value, 'i') },
                ],
            });
        }
    },
});

extendedResolver.name = 'pagination';
userTypeComposer.addResolver(extendedResolver);

GQC.rootQuery().addFields({
    userById: userTypeComposer.getResolver('findById'),
    users: userTypeComposer.getResolver('pagination'),
});

GQC.rootMutation().addFields({
    userCreate: userTypeComposer.getResolver('createOne'),
});

console.dir(userTypeComposer.getResolver('findOne').getArg('filter').removeField);
console.dir(userTypeComposer.getResolver('findOne').getArg('filter').removeArg);

undefined
undefined

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024
[1] hbt-api-de | { type: 
[1] hbt-api-de |    GraphQLInputObjectType {
[1] hbt-api-de |      name: 'FilterFindOneUserInput',
[1] hbt-api-de |      description: undefined,
[1] hbt-api-de |      astNode: undefined,
[1] hbt-api-de |      _typeConfig: { name: 'FilterFindOneUserInput', fields: [Function] } },
[1] hbt-api-de |   name: 'filter',
[1] hbt-api-de |   description: 'Filter by fields' }
[1] hbt-api-de | 
[1] { type: 
[1] hbt-api-de |    GraphQLInputObjectType {
[1] hbt-api-de |      name: 'FilterFindOneUserInput',
[1] hbt-api-de |      description: undefined,
[1] hbt-api-de |      astNode: undefined,
[1] hbt-api-de |      _typeConfig: { name: 'FilterFindOneUserInput', fields: [Function] } },
[1] hbt-api-de | 
[1]   name: 'filter',
[1] hbt-api-de |   description: 'Filter by fields' }

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

Agr, sorry for late response.

getArg - returns arg config { type, description, deprecationReason, defaultValue }

For working with type need to use getArgTC which returns InputTypeComposer which can modify arg type.

https://github.com/nodkz/graphql-compose/blob/bb834cb03c43989571881e4aa27bef2194918829/src/resolver.js#L107-L115

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024

@nodkz console.log(userTypeComposer.getResolver('pagination').getArgTC('sort'));

[1] Error: Cannot get InputTypeComposer for arg 'sort' in resolver User.pagination(User.pagination). This argument should be InputObjectType, but it has type 'GraphQLEnumType'
[1] hbt-api-de |     at Resolver.getArgTC (/Users/ivan.zubok/PhpstormProjects/hbt-group/backend/node_modules/graphql-compose/lib/resolver.js:123:15)
[1] hbt-api-de |     at Object.<anonymous> (/Users/ivan.zubok/PhpstormProjects/hbt-group/backend/modules/user/types/index.ts:29:56)
[1] hbt-api-de |     at Module._compile (module.js:569:30)
[1] hbt-api-de |     at Object.Module._extensions..js (module.js:580:10)
[1] hbt-api-de |     at Module.load (module.js:503:32)
[1] hbt-api-de |     at tryModuleLoad (module.js:466:12)
[1] hbt-api-de |     at Function.Module._load (module.js:458:3)
[1] hbt-api-de |     at Module.require (module.js:513:17)
[1] hbt-api-de |     at require (internal/module.js:11:18)

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

This is expected behavior. InputTypeComposer can work only on complex input types with fields. Enum is a scalar type (like String, Int, Boolean).

Frankly graphql-compose does not allow to modify Enum types. I want to add EnumTypeComposer for adding/removing values from GraphQLEnum but I do not have any ETA when it will land.

Anyway you may manually edit Enums in such way https://github.com/nodkz/graphql-compose/blob/bb834cb03c43989571881e4aa27bef2194918829/src/resolver.js#L514-L536

from graphql-compose-mongoose.

akaNightmare avatar akaNightmare commented on May 12, 2024

@nodkz thanks, please keep it issue until you add EnumTypeComposer, or I will try add it by myself.

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

Close this issue due "nothing to-do with graphql-compose-mongoose".

Open new issue about EnumTypeComposer implementation in right place/package graphql-compose/graphql-compose#79
Please keep track there.

from graphql-compose-mongoose.

chanm003 avatar chanm003 commented on May 12, 2024

How would I exclude a sub-field?
My query looks like this:

query {
    UserMany {
        _id
        firstName
        lastName
        local {
            password
        }
}

I tried the following and neither seems to work:

UserTC.removeField('local.password');
UserTC.removeField('local').removeField('password');

from graphql-compose-mongoose.

nodkz avatar nodkz commented on May 12, 2024

@chanm003
UserTC.getFieldOTC('local').removeField('password').

PS. Removing fields via dot-notation is a good feature request. I will add it later.

from graphql-compose-mongoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.