how to get specific value
in this example
how to get value of skill for English language skills only not list all languages skills ??
is there any easy solution ? I will make a separate title schema for skills with Add relation for them and use search , I don't know if it will work as I wont or not ! also the problem I have many cases like that, it'll be hard to add a separate file for every case .
You may add a new field with your filtering logic. Eg.
UserTC.setField('languageSkill', {
type: 'String', // output type
args: { language: 'String!' }, // your argument which will accept language
resolve: (source, args) => {
if (!source.languages) return null;
const t = source.languages.filter(o => o && o.language === args.language);
return t[0] ? t[0].skill : null;
},
projection: { languages: 1 }, // need for requesting `languages` from server
});
If you have many places where you need to add the same custom logic, just write your helper function, which accept TypeComposer makes some modifications and return them back:
function extendBySuperLogic(tc: TypeComposer): TypeComposer {
tc.setField(...);
tc.addFields(...);
tc.extendField(...);
tc.some_other_methods
return tc;
}
I got an error
export const UserTC = composeWithRelay(composeWithMongoose(User));
UserTC.addField('languageSkill', {
type: 'String', // output type
args: { language: 'String!' }, // your argument which will accept language
resolve: (source, args) => {
if (!source.languages) return null;
const t = source.languages.filter(o => o && o.language === args.language);
return t[0] ? t[0].skill : null;
},
projection: { languages: 1 }, // need for requesting `languages` from server
});
TypeError: UserTC.addField is not a function
I think you can use UserTC.addFields()
Oh, my miss. May be used such methods:
setField(name, config);
Or
addFields({
name1: config1
name2: config2
});