i have a simple favourite query which tells if an item is favourite to a person
g.V().has('personId','3f857b1').choose(identity().out('favourite').has('itemId','48a680b'),constant('Already_favourite'),choose(V().has('itemId','48a680b'),constant('NotFavourite'),constant('InvalidItem')))
is it a bad practice to write nested choose steps as it is in other programming languages
i wanted to know if we could implement stored procedures in gremlin
is it a bad practice to write nested choose steps
No, but I would still write your query differently. Don't waste compute time and stop the traversal quickly, if the item doesn't exist. On the other hand, if it exists, try to find it by its id; don't fetch the itemId
property for every adjacent vertex:
result = g.V().has('itemId', '48a680b').as('item').
V().has('personId','3f857b1').coalesce(
out('favourite').where(eq('item')).constant('Already_favourite'),
constant('NotFavourite')).tryNext().orElse('InvalidItem');