[REQUEST] Disambiguate the productId field
snowteamer opened this issue · 4 comments
Is your feature request related to a problem? Please describe.
It is currently not possible to query our sample database using the productId
as query argument.
- Product objects in the sample db don't have that field.
- According to the current docs, it should be a string like
"y3u2uy32"
- In the mongoose schema, it is declared as ObjectID
Describe alternatives you have considered
- Declare
productId
as a String in the mongoose schema (maybe with attributesrequired
andmaxlength
) - Drop that field since we already have the default
id
, or rename it to something easy to understand according to the product category ? For example books have ISBN number, some products have a serial number, etc.
The productId
could also be defined as a read-only virtual alias of the default mongoose id
, like:
productSchema.virtual('productId').get(function get() {
return this._id;
});
Sure. This seems logical as we won't update the field or anything.
After some tests it appears that this would prevent saving updated product objects, because the field is also marked as required
in the schema.
So I think we will have to either
- copy the value of the
id
field into theproductId
field whenever we create a Product object. This would duplicate the value, but allow simpler code in the resolver - not use the
required
attribute on the field. Accessing the field would still be guaranteed to return a value as long as the default_id
is defined
I would favor the first approach if later we might use a product id which would no longer be the same as the default id.
I would favor the first approach if later we might use a product id which would no longer be the same as the default id.
Go for it.