when a fragment has a directive @refetchable, compiler will generate a refetch query.
when refetch, I expect it is like the initial query, which has a directive defined on server side.
but it does NOT, the generated persist query has no the directive, and I read some code in compiler,
RefechableFragmentTransform.js
the expected behavior is not implemented.
I try to add the implementation, now it works, but still not completed. if need, I can paste it.
my question is whether it will be implemented. (I thought it should be implemented, )
Try to send a PR
EDIT: I just realized that this was discussed in the #relay slack channel. Adapting my response there - it looks like your use-case can be boiled down to something like:
query ParentQuery @query_directive {
...Fragment
}
fragment Fragment @refetchable(...) { ... }
Where you're expecting the generated refetch query to have @query_directive on it - unfortunately that won't work. The way @refetchable works is that it's purely based on the definition of the fragment. That fragment could be spread in lots of different places, underneath queries with lots of different directives. If the compiler were to try to apply directives from those queries to the fragment's refetch query, it wouldn't be clear which query's directives to even use (Imagine that there is also query ParentQuery2 { ...Fragment } - with different directives).
What _should_ work is that if the fragment definition has directives on it -fragment Foo @refetchable(...) @fragment_directive, then we should be copying that @fragment_directive to the refetch query. If that isn't happening please let us know!
@josephsavona
Writing ts
ERROR:
- Invalid directives @withUser found on FRAGMENT_DEFINITION.
home/main.tsx:3:3
2 | fragment mainLinksForMe on Query
3 | @withUser(isVendorUser: $isVendorUser)
| ^
4 | @refetchable(queryName: "MainLinksForMeQuery") {
error Command failed with exit code 100.
That error indicates that you have defined the @withUser directive as only being valid on queries. If you want to use one of your application-defined directives on a fragment, you have to define it in your schema as being allowed on fragment definitions too.
That error indicates that you have defined the
@withUserdirective as only being valid on queries. If you want to use one of your application-defined directives on a fragment, you have to define it in your schema as being allowed on fragment definitions too.
now I see, thank you.
and I have not met the problem you said that in case of different query reference the same refetch fragment. I will continue use the fix until it breaks.
Most helpful comment
That error indicates that you have defined the
@withUserdirective as only being valid on queries. If you want to use one of your application-defined directives on a fragment, you have to define it in your schema as being allowed on fragment definitions too.