Comments (14)
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.
@nodkz is it possible to pick fields(removeOtherFields
?)?
from graphql-compose-mongoose.
Yep, removeOtherFields
May be better to rename this method. pickFields
also not a good name.
from graphql-compose-mongoose.
console.log(userTypeComposer.getResolver('findOne').getArg('filter').removeField);
console.log(userTypeComposer.getResolver('findOne').getArg('filter').removeArg);
undefined
undefined
from graphql-compose-mongoose.
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.
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.
[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.
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.
from graphql-compose-mongoose.
@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.
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.
@nodkz thanks, please keep it issue until you add EnumTypeComposer
, or I will try add it by myself.
from graphql-compose-mongoose.
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.
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.
@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)
- Can't filter response by fields HOT 4
- Correct error handling in mutations HOT 2
- Unable to compose schema for discriminator with index HOT 1
- Array field UpdateMany - $set as object instead of $push array
- beforeRecordMutate not firing HOT 2
- Internal error occurred during message handling. Please check your implementation. Error: Subscription field must return Async Iterable. Received: undefined. HOT 1
- Relation detection HOT 4
- feat: Introduce subscription resolvers using Mongoose Watch
- Inconsistency with mongoose custom types
- Unable to use _operator while filtering a connection HOT 1
- graphql-compose-mongoose with Typescript without extending Document HOT 2
- removeMany throw an error if no items to delete with mongoose v6
- Preserve the array order when using findbyIds HOT 2
- unique type option in mongoose does not work with graphql-compose-mongoose
- If a TC's findMany resolver is added to schema multiple times, filter options for subsequent resolvers are ignored HOT 2
- Type 'Cat' is not assignable to type 'Document<any, any, any>' HOT 2
- Mongoose 7 issue ( graphql type and doc validate ) HOT 1
- Array items are generated as optional
- Provide collection name from request
- Incompatible with mongoose 8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-compose-mongoose.