ferry
ferry copied to clipboard
Union type issue for flutter web on release build mode
When running the release build for flutter web, this error has occurred. Our graphql api returns a union type (please see schema below). Note that it's working well on debug mode and this only happens on release build.
main.dart.js:4234 Uncaught TypeError: Instance of 'minified:H0': type 'minified:H0' is not a subtype of type 'minified:ka'
at Object.c (main.dart.js:4234:3)
at Object.aMC (main.dart.js:4856:18)
at kz.b1i [as a] (main.dart.js:4851:3)
at kz.b1x (main.dart.js:4823:10)
at main.dart.js:78762:13
at az2.a (main.dart.js:5427:62)
at az2.$2 (main.dart.js:39326:14)
at Object.I (main.dart.js:5413:10)
at as0.WN (main.dart.js:78796:10)
at as0.$1 (main.dart.js:78751:19)
The issue occurred after executing this request,
client.request(request).listen((res) async {
if (res.hasErrors) {
....
return;
}
final data = res.data?.memberLogin;
if (data?.G__typename == 'Member') {
final res = data as GMemberLoginData_memberLogin__asMember ;
....
} else if (data?.G__typename == 'EmailRegistration') {
final res = data as GMemberLoginData_memberLogin__asEmailRegistration;
...
}
});
When I logged the data
from the response above, I only got this information.
GMemberLoginData {
G__typename=GuestMutation,
memberLogin=GMemberLoginData_memberLogin__base {
G__typename=Member ,
},
}
Mutation
mutation MemberLogin($foo: String!, $foo1: String!) {
memberLogin(foo: $foo, foo1: $foo1) {
... on EmailRegistration {
__typename
somefield
}
... on Member {
__typename
somefield
}
}
}
Schema
type Mutation {
memberLogin(foo: String!, foo1: String!): LoginResult!
}
union LoginResult = Member | EmailRegistration
Anyone have an idea regarding this issue?
I'm also seeing this issue on web in release mode, does anyone know a workaround?
Running into this also. Seeing the same thing as the OP, it prints out the __base type instead of the concrete type. In debug mode the concrete type is printed out as expected.
Only workaround I've found is to build web in profile mode.
Running into the same issue now while trying to port our production app to web.
Has anyone been able to patch this?
@smkhalsa I understand you've been busy with other projects, but could you share your thoughts on what might be causing this issue?
@Rydeard The fix is checked into gql-dart https://github.com/gql-dart/gql/commit/85f6df5c785844a96c1e49b772b16e2f61a793b1 . You will have to fork ferry and update it to grab the latest gql-dart, until the ferry dependencies are updated.