ferry icon indicating copy to clipboard operation
ferry copied to clipboard

Support for @include and @skip directives in normalize

Open mlars84 opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. Attempting to use the @include or @Skip directives in graphql_flutter results in a PartialDataException. This would be a great feature for re-using queries in multiple places where some fields may not be needed in all cases.

Describe the solution you'd like I'd like the @include directive to work as one would expect:

  • If false, the decorated field or fragment in an operation is not resolved by the GraphQL server and the @Skip directive to work as one would expect:
  • If true, the decorated field or fragment in an operation is not resolved by the GraphQL server.

Describe alternatives you've considered An alternative might be to create separate queries for each use case, but that defeats the goal of reusability.

Additional context Thanks for considering!

mlars84 avatar Oct 07 '22 21:10 mlars84

Valid point.

I believe until this is implemented, as a workaround you might be able to set the flag returnPartialData to true to avoid getting PartialDataExceptions (I don't know if graphql_flutter exposes this flag though)

knaeckeKami avatar Oct 07 '22 21:10 knaeckeKami

A draft implementation is available in #433 .

Feedback would be appreciated.

knaeckeKami avatar Oct 09 '22 13:10 knaeckeKami

I complete implementation of this is more work than I though. On fields it's pretty straight forward, but this Directives can also be set on fragments and inline fragments, and fields can be specified multiple times (once directly, once in an inline fragment).

So an adaption of this algorithm is needed. I will work on it, but it will take some more time.

knaeckeKami avatar Oct 16 '22 20:10 knaeckeKami

@mlars84 If you like, you can try using the state of this PR on normalize as a dependency override:

https://github.com/gql-dart/ferry/pull/433

This should add support for skip/include for fields, fragments on inline fragments.

If you run into any problems, please let me know!

knaeckeKami avatar Oct 30 '22 18:10 knaeckeKami

published normalized: 0.8.0-dev.0

I decided to go for a breaking change release (with a bumped minor version number on a 0.x ) version, because I think code generators might need to be also adapted for nullability on skip/include directives and so the package maintainers of graphql clients should opt-in to this change when they are ready.

If you don't use any code generators, I think you can just a dependency_override.

knaeckeKami avatar Oct 30 '22 19:10 knaeckeKami

Thanks @knaeckeKami!

mlars84 avatar Oct 31 '22 14:10 mlars84