Apollo-client: Feature request: cache API to find all entities by __typename

Created on 7 Aug 2020  路  1Comment  路  Source: apollographql/apollo-client

Let say i have employees under root query (Parent-> Child-> employees (...variables) {_id name email} ) somewhere. I would like to load all the employee using my custom query in typepolicity.
I tried to play with toRefernce without passing any Id since I want to load all the employee but was not successfull.

Query: {
        fields: {
          myCustomLoadAllTheEmployee(_, { args, toReference }): unknown {
            return toReference({
              __typename: 'Employee',
            });
          },
       }
}

So, my question is, how can I load all the entities when I only know the __typename.?

idea 馃崻 feature-request 馃挰 discussion

Most helpful comment

There's no good way to do this right now (toReference needs not only the __typename but also any primary key fields, and only returns a reference to a single object), but I agree it would be useful to have some way of querying the cache that goes beyond what GraphQL query syntax allows. Of course, that would make the cache feel more like a general-purpose graph database, which raises all sorts of possibilities, like building indexes on certain fields (like __typename) to improve performance.

>All comments

There's no good way to do this right now (toReference needs not only the __typename but also any primary key fields, and only returns a reference to a single object), but I agree it would be useful to have some way of querying the cache that goes beyond what GraphQL query syntax allows. Of course, that would make the cache feel more like a general-purpose graph database, which raises all sorts of possibilities, like building indexes on certain fields (like __typename) to improve performance.

Was this page helpful?
0 / 5 - 0 ratings