You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
Before reporting a bug, please test the beta branch!
Bug description
For now it's pretty hard to use generated classes from "union" type;
For example now, to identify object and use it's field i need to use this construction:
query xxx {
sometype: {
...on X {
onlyXField
}
...on Y {
onlyYField
}
...on Z {
onlyZField
}
}
}
if (parsedObject is X) {
return x.onlyXField;
}
if (parsedObject is Y) {
return y.onlyYField;
}
if (parsedObject is Z) {
return z.onlyZField;
}
// unsupported type
return error;
and if i use mixin (fragments inside queries), then i'd have to:
if (parsedObject is X) {
return (x as XMixin).onlyXField;
}
if (parsedObject is Y) {
return (y as XMixin).onlyYField;
}
if (parsedObject is Z) {
return (z as XMixin).onlyZField;
}
// unsupported type
return error;
Just came here to request the exact same thing then saw it top of the list. On our project we use unions to model the possible error results from a mutation or query so we pretty much have a union on every single operation. We use freezed for the rest of the app so currently we map the result types into a freezed union as soon as we get the result back. It's a ton of boiler plate though so having this in the generator would have a big impact on ergonomics.
And I'm conditionally setting state via StateNotifier based on the type response. Would be sweet if this could be automatic somehow. Not sure how that would work. Example:
// Copy result to state (UNION CONDITIONAL STATE)final resultData = result.data?.getMode;
if (resultData isGetMode$Query$GetMode$Failure) {
state = state.copyWith(failure: resultData, data:null);
} elseif (resultData isGetMode$Query$GetMode$ModeResponse) {
state = state.copyWith(failure:null, data: resultData);
} else {
state = state.copyWith(failure:null, data:null);
}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Before reporting a bug, please test the beta branch!
Bug description
For now it's pretty hard to use generated classes from "union" type;
For example now, to identify object and use it's field i need to use this construction:
and if i use mixin (fragments inside queries), then i'd have to:
with "freezed" it would be something like this:
The text was updated successfully, but these errors were encountered: