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
@smkhalsa Issue created from our DIscord discussion
A custom serializer's return type that is imported from another file is not shown in serializers.gql.dart causing a build error.
Only happens with generated BuiltLists? I have other custom scalars set-up the same way but addBuilderFactory functions are not generated for them so this problem doesn't occur...
Also, the addBuilderFactory function is generated multiple times...
Note: build_runner build is still successful
Error
lib/graphql/schema/serializers.gql.g.dart:182:59: Error: Getter not found: 'MyModel'.
const FullType(BuiltList, const [const FullType(MyModel)]),
^^^^^^^^^^^^^^
lib/graphql/schema/serializers.gql.g.dart:183:33: Error: 'MyModel' isn't a type.
() => new ListBuilder<MyModel>())
^^^^^^^^^^^^^^
// my_model_serializer.dart// ignore: implementation_importsimport'package:gql_code_builder/src/serializers/json_serializer.dart';
// This import exposes "MyModel" which will be required, but missing, from serializers.gql.dartimport'package:flutter_app/models/my_model.dart';
classMyModelSerializerextendsJsonSerializer<MyModel> {
@overrideMyModelfromJson(Map<String, dynamic> data) {
returnMyModel.fromJson(data);
}
@overrideMap<String, dynamic> toJson(MyModel model) {
return model.toJson();
}
}
// serializers.gql.dart//...// Correctly exposes "MyModelSerializer" but NOT "MyModel", causing built file to have missing typeimport'package:flutter_app/graphql/serializers/my_model_serializer.dart'show MyModelSerializer;
part'serializers.gql.g.dart';
finalSerializersBuilder _serializersBuilder = _$serializers.toBuilder()
..add(OtherSerializer())
..add(MyModelSerializer())
//...
adding the missing import MyModel into serializers.gql.dart fixes the issue, but I still haven't dug deep enough into built_value to see why/where it's adding those builder factories, and why it's only doing it for the list item and not the other overrides
@danielmahon built_value generates the serializers.gql.g.dart file based on the contents of your serializers.gql.dart.
I don't actually think this has anything to do with the custom serializer. built_value is building the BuilderFactories because one of your GraphQL operations uses a BuiltList<MyModel>, and BuilderFactories are what tell built_value how to serialize BuiltLists of non-standard types.
The easiest solution would be to just include an import of any type overrides by default. I've created PR #148 which implements this. Can you please confirm that it fixes the issue? NOTE: you will need to include your type_overrides map in the serializer_builder in your build.yaml file.
A more elegant solution that selectively imports the custom types only when they will be used in a BuilderFactory would not be trivial, and I think this solution is probably good enough.
@smkhalsa Issue created from our DIscord discussion
A custom serializer's return type that is imported from another file is not shown in
serializers.gql.dart
causing a build error.Only happens with generated BuiltLists? I have other custom scalars set-up the same way but
addBuilderFactory
functions are not generated for them so this problem doesn't occur...Also, the
addBuilderFactory
function is generated multiple times...Note:
build_runner build
is still successfulError
Example
The text was updated successfully, but these errors were encountered: