aerogear / offix

GraphQL Offline Client and Server
https://offix.dev
Apache License 2.0
758 stars 45 forks source link

Ability to provide late binding for datastore queries. #891

Closed wtrocki closed 3 years ago

wtrocki commented 4 years ago

Feature Request

The query for datastore might not be known at the moment of creating the store. For example, logged user ID needs to be retrieved etc.

wtrocki commented 4 years ago

CC @kingsleyzissou

wtrocki commented 4 years ago

Generally we will need to be able to start replication separately to model setup. So we might have startReplication method on model and this can be triggered from app/components itself.

kingsleyzissou commented 4 years ago

This is a good point, starting replication automatically might not be desired behaviour in most cases.

kingsleyzissou commented 3 years ago

@wtrocki

Regarding this, what I'm thinking of doing here is removing the replication config as a parameter to the setup model method here:

https://github.com/aerogear/offix/blob/29bd06cde71626b67c91042d92533ad6114b40b5/packages/datastore/datastore/src/DataStore.ts#L57

Then we can add another function called applyReplicationFilters where we can add filters to our replication config in React context and then init the datastore once that has been set. If no filters have been applied, we could use the default config at that point.

Do you see any downsides to this approach?

wtrocki commented 3 years ago

How and when are we going to start replication? Would this mean that if someone doesn't add filter things will never replicate?

kingsleyzissou commented 3 years ago

The idea would be to start replication in context, but start it later. If a filter isn't provided, we can revert to the default config. Alternatively, we could keep it as is and use the context to update the filters for the replication config for each model.

wtrocki commented 3 years ago

Sounds like plan

kingsleyzissou commented 3 years ago

Okay after initial investigation, we will have to do a startReplication method on the server. I will drop a work in progress PR sometime today.

I need to defer the building of the graphql schemas until after we've applied the filter, but I will put some comments on the code to highlight this.

kingsleyzissou commented 3 years ago

1016 closes this issue