dojo icon indicating copy to clipboard operation
dojo copied to clipboard

Update gRPC queries

Open broody opened this issue 1 year ago • 8 comments

Proposal to update gRPC endpoint to be more flexible. Currently, the Retrieve Entities endpoint can support three different types of queries. We talked adding an additional composite query, however, thinking about it more I feel like just updating existing queries could provide the required flexibility and also closely mimic graphql queries.

  • entities_by_hashed_keys - no changes, input an array of hashed_keys and returns corresponding entities. Returns all entities if no hashed_keys supplied.

  • entities_by_keys - currently requires model_name and an array of keys. The reason for model_name is for more efficient queries since it returns only entities of that type. The change here is to make model_name optional, so it can return all entities matching supplied keys.

  • entities_by_member - returns entities matching a comparison operation on one member of a single model. Change this to entities_by_members (plural) and take multiple models and comparison operators on multiple members. This is effectively the composite query and pretty similar to what we have in gql.

@Larkooo @ponderingdemocritus @RareSecond let me know what you guys think and if there are q's

broody avatar Mar 06 '24 00:03 broody

If we have entities_by_members why would we still need entities_by_keys? From a querying standpoint, we shouldn't really care about if a search field is a key or not.

RareSecond avatar Mar 06 '24 08:03 RareSecond

Makes sense, I indeed think that the added composite query just adds complexity. One nice thing maybe is that with the composite query you could fetch entities_by_member + entities_by_hashed_keys. But I dont think it'll be very useful in a lot of cases

Larkooo avatar Mar 06 '24 16:03 Larkooo

If we have entities_by_members why would we still need entities_by_keys? From a querying standpoint, we shouldn't really care about if a search field is a key or not.

If you're querying for entire entities, the easiest way to filter on them is through the keys param since an entity is a collection of models that are associated by its keys. Looking at the interface propsal here, what we really also want is a models query, returning only specific models matching search fields and not entire entities.

broody avatar Mar 06 '24 17:03 broody

I'm not sure if I'm entirely following @broody. Could you give concrete examples of the differences?

RareSecond avatar Mar 07 '24 07:03 RareSecond

The first query requires just the keys array, while the second requires model name and member field params. Perhaps models_by_members is a better name for the second one.

broody avatar Mar 07 '24 17:03 broody

But we can't work with the first one if we want full type safety, no? Because we need to know what models to expect back

On Thu, Mar 7, 2024, 18:19 Yun @.***> wrote:

The first query requires just the keys array, while the second requires model name and member field params. Perhaps models_by_members is a better name for the second one.

— Reply to this email directly, view it on GitHub https://github.com/dojoengine/dojo/issues/1613#issuecomment-1984043518, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2R5BW43CHF274QGGROE2DYXCOR5AVCNFSM6AAAAABEIDOV56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBUGA2DGNJRHA . You are receiving this because you commented.Message ID: @.***>

RareSecond avatar Mar 07 '24 21:03 RareSecond

Yes, for type safety use the second one, tho the side effect is you'll only receive entities consisting of specified models

broody avatar Mar 08 '24 01:03 broody

Some previous work to keep in mind some changes that were planned: #1638.

glihm avatar Jun 27 '24 03:06 glihm

Will close for now with the rework of composite queries. Will re-open more detailed issues based on the work to be achieved on gRPC and coming features.

glihm avatar Nov 08 '24 04:11 glihm