You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, I have a type that exits in two schemas, each schema exposes different fields e.g. public/private fields. I want to see what's peoples opinions on this approach?
constFIELD_DEFINTIONS={id: {type: 'String'},private: {type: 'String',resolve: ()=>'private'},public: {type: 'String',resolve: ()=>'public'},};functionmyTypeFields(t,projection){constfields=projection ? projection(FIELD_DEFINTIONS) : FIELD_DEFINTIONS;for(const[fieldName,fieldDef]ofObject.entries(fields)){t.field(fieldName,fieldDef);}}// usage in schema AconstThingA=objectType({name: 'Thing',definition(t){// get all the fieldsmyTypeFields(t);t.string('other',()=>'other')},});// usage in schema BconstThingB=objectType({name: 'Thing',definition(t){// pass in a projection function to grab only what you need, and rename if needed.myTypeFields(t,(fields)=>({id: fields.id,publicThing: fields.public}));t.string('other',()=>'other')},});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there, I have a type that exits in two schemas, each schema exposes different fields e.g. public/private fields. I want to see what's peoples opinions on this approach?
Beta Was this translation helpful? Give feedback.
All reactions