urql-graphql / urql-exchange-graphcache

A normalized and configurable cache exchange for urql
88 stars 13 forks source link

Directive composition #152

Open JoviDeCroock opened 4 years ago

JoviDeCroock commented 4 years ago

Idea

Related to https://github.com/FormidableLabs/urql-exchange-graphcache/issues/146 I'd like to extend our traverser to have a certain set of directives like the one proposed in the issue @extra. When passed to the cacheExchange it would automatically stop at these directives, strip them out and execute a callback allowing you to return an altered operation, ....

This would for example allow you to add more variables, allow the populateExchange to become a HOC passed into this object.

Rough example

cacheExchange({
  directives: {
    extra: (op, directiveArgs) => ({ ....op, variables: { ...op.variables, ...directiveArgs }}) 
  }
})

This is very rough and I'll most likely alter this when hacking on it but I would like to send this in to get some more idea's

andyrichardson commented 4 years ago

I think the order importance of exchanges is a bit of a pain but I'm not sure nesting them inside the cache is the way to go.

Are there any specific decorators that can't be resolved before/after the cache?

JoviDeCroock commented 4 years ago

Are there any specific decorators that can't be resolved before/after the cache?

No but I'm trying to find a middle ground on this. Much like for instance redux has middlewares it could be used to make our cache smarter (and we need to solve the issue anyway so I thought let's look for a very extendable solution)

kitten commented 4 years ago

I think it's sufficient to fix https://github.com/FormidableLabs/urql-exchange-graphcache/issues/146 in isolation :)

JoviDeCroock commented 4 years ago

@kitten do you agree with @andyrichardson to catch a directive like extra in a separate exchange?