Support for @include and @skip directives in normalize
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!
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)
A draft implementation is available in #433 .
Feedback would be appreciated.
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.
@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!
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.
Thanks @knaeckeKami!