@@ -13,22 +13,22 @@ import 'package:graphql_codegen/src/printer/utils.dart';
1313
1414List <Spec > printInputClasses (PrintContext <ContextInput > context) =>
1515 _printInputClasses (
16- context,
17- context.namePrinter.printClassName,
18- context.context.properties,
16+ context: context ,
17+ name : context.namePrinter.printClassName,
18+ properties : context.context.properties,
1919 );
2020
2121List <Spec > printVariableClasses (PrintContext context) => _printInputClasses (
22- context,
23- context.namePrinter.printVariableClassName,
24- context.context.variables,
22+ context: context ,
23+ name : context.namePrinter.printVariableClassName,
24+ properties : context.context.variables,
2525 );
2626
27- List <Spec > _printInputClasses (
28- PrintContext context,
29- String Function (Name ) name,
30- Iterable <ContextProperty > properties,
31- ) {
27+ List <Spec > _printInputClasses ({
28+ required PrintContext context,
29+ required String Function (Name ) name,
30+ required Iterable <ContextProperty > properties,
31+ } ) {
3232 final factoryParameters = ListBuilder <Parameter >(
3333 properties.map (
3434 (property) => Parameter (
@@ -51,31 +51,65 @@ List<Spec> _printInputClasses(
5151 (b) => b
5252 ..name = name (context.path)
5353 ..constructors = ListBuilder ([
54- Constructor (
55- (b) => b
56- ..factory = true
57- ..optionalParameters = factoryParameters
58- ..body = refer (name (context.path)).property ('_' ).call ([
59- CodeExpression (Code (
60- """
54+ if (context.context.isOneOf)
55+ ...properties.map (
56+ (property) => Constructor (
57+ (b) => b
58+ ..requiredParameters = ListBuilder ([
59+ Parameter (
60+ (b) => b
61+ ..name = context.namePrinter.printPropertyName (
62+ property.name,
63+ )
64+ ..type = asNonNullable (
65+ printClassPropertyType (
66+ context,
67+ property,
68+ ),
69+ ),
70+ )
71+ ])
72+ ..factory = true
73+ ..name = context.namePrinter.printPropertyName (property.name)
74+ ..body = refer (name (context.path)).property ('_' ).call ([
75+ literalMap (
76+ {
77+ property.name.value: refer (
78+ context.namePrinter.printPropertyName (
79+ property.name,
80+ ),
81+ ),
82+ },
83+ ),
84+ ]).code,
85+ ),
86+ )
87+ else
88+ Constructor (
89+ (b) => b
90+ ..factory = true
91+ ..optionalParameters = factoryParameters
92+ ..body = refer (name (context.path)).property ('_' ).call ([
93+ CodeExpression (Code (
94+ """
6195 {
6296 ${properties .map ((property ) {
63- final key = property .name .value ;
64- final value =
65- context .namePrinter .printPropertyName (property .name );
66- final entry = "r'${key }': ${value }," ;
67- if (property .isRequired ) {
68- return entry ;
69- }
70- return """
97+ final key = property .name .value ;
98+ final value =
99+ context .namePrinter .printPropertyName (property .name );
100+ final entry = "r'${key }': ${value }," ;
101+ if (property .isRequired ) {
102+ return entry ;
103+ }
104+ return """
71105 if (${value } != null) ${entry }
72106 """ ;
73- }).join ()}
107+ }).join ()}
74108 }
75109 """ ,
76- )),
77- ]).code,
78- ),
110+ )),
111+ ]).code,
112+ ),
79113 Constructor ((b) => b
80114 ..name = '_'
81115 ..requiredParameters = ListBuilder ([
0 commit comments