This might be more of a general JS question, instead of Apollo specific, but just giving it a try.
I’m on the verge of “throwing” everything DDP/Minimongo related out the door, and just bite the bullet by switching to Apollo. One thing I can’t put my finger on yet how I would fix it in Apollo though. It’s related to computed fields.
Currently I have js prototypes per object type I have specified in Mongo. That way I can add computed fields (e.g., a computed price field) to the objects returned from the Collection. Using the “transform” function of the collection and applying my prototypes to them.
How could/would this work in an Apollo world? A very simple hello world example
{ name: 'foo', unit_price: 1, amount: 100 }
Is stored in Mongo. In the prototype I add a computed field “value”. e.g.
The the collection would say: const Products = new Mongo.Collection('products', { transform(doc) { return _.extend(Object.create(PricePrototype), doc); }, });
Does this approach still makes sense with GraphQL/Apollo? Meaning, the app won’t have complete “objects” anymore if I get it correctly. So you work with shards of properties of something instead of whole instances. Does it then make more sense to externalize that Helper? Curious how people handle this use case currently.
To be honest, it should be even easier in Apollo than you have currently, you add the computed field name to the schema for the object you are after and then in the resolver simply return the calculation.