@@ -202,22 +202,14 @@ and generate_nullable_decoder = (config, loc, inner) =>
202202and generate_array_decoder = (config, loc, inner) =>
203203 [@ metaloc loc]
204204 {
205- switch %expr (Js . Json . decodeArray(value)) {
206- | None =>
207- % e
208- make_error_raiser(
209- [% expr "Expected array, got " ++ Js . Json . stringify(value)],
210- )
211- | Some (value ) =>
212- Js . Array . map(
213- value => {
214- let _ = () ;
215- % e
216- generate_decoder(config, inner);
217- },
218- value,
219- )
220- };
205+ % expr
206+ value
207+ |> Js . Json . decodeArray
208+ |> Js . Option . getExn
209+ |> Js . Array . map(value => {
210+ % e
211+ generate_decoder(config, inner)
212+ });
221213 }
222214and generate_custom_decoder = (config, loc, ident, inner) => {
223215 let fn_expr =
@@ -374,89 +366,83 @@ and generate_object_decoder = (config, loc, name, fields) => {
374366 make_obj_constructor_fn(i + 1 , next),
375367 );
376368 [@ metaloc loc]
377- (
378- switch %expr (Js . Json . decodeObject(value)) {
379- | None =>
380- % e
381- make_error_raiser([% expr "Object is not a value" ])
382- | Some (value ) =>
383- % e
384- Ast_helper . Exp . letmodule(
385- {txt: "GQL" , loc: Location . none},
386- Ast_helper . Mod . structure([
387- Ast_helper . Str . primitive({
388- pval_name: {
389- txt: "make_obj" ,
390- loc: Location . none,
391- },
392- pval_type: make_obj_constructor_fn(0 , fields),
393- pval_prim: [ "" ] ,
394- pval_attributes: [
395- ({txt: "bs.obj" , loc: Location . none}, PStr ([] )),
396- ] ,
397- pval_loc: Location . none,
398- }),
399- ] ),
400- Ast_helper . Exp . apply(
401- Ast_helper . Exp . ident({
402- txt: Longident . parse("GQL.make_obj" ),
369+ {
370+ let %expr value = value |> Js.Json.decodeObject |> Js.Option.getExn;
371+
372+ %e
373+ Ast_helper . Exp . letmodule (
374+ {txt: "GQL" , loc: Location . none },
375+ Ast_helper . Mod . structure ([
376+ Ast_helper . Str . primitive ({
377+ pval_name: {
378+ txt: "make_obj" ,
403379 loc: Location . none ,
404- }),
405- List . append(
406- fields
407- |> List . map(
408- fun
409- | Fr_named_field (key , _ , inner ) => (
380+ },
381+ pval_type: make_obj_constructor_fn (0 , fields ),
382+ pval_prim: [ "" ] ,
383+ pval_attributes: [
384+ ({txt: "bs.obj" , loc: Location . none }, PStr ([] )),
385+ ] ,
386+ pval_loc: Location . none ,
387+ }),
388+ ] ),
389+ Ast_helper . Exp . apply (
390+ Ast_helper . Exp . ident ({
391+ txt: Longident . parse ("GQL.make_obj" ),
392+ loc: Location . none ,
393+ }),
394+ List . append (
395+ fields
396+ |> List . map (
397+ fun
398+ | Fr_named_field (key , _ , inner ) => (
399+ Labelled (key ),
400+ switch %expr (Js . Dict . get (value , [%e const_str_expr (key )])) {
401+ | Some (value) =>
402+ %e
403+ generate_decoder(config, inner)
404+ | None =>
405+ if%e (can_be_absent_as_field(inner)) {
406+ %expr
407+ None;
408+ } else {
409+ make_error_raiser(
410+ [%expr
411+ "Field "
412+ ++ [%e const_str_expr(key)]
413+ ++ " on type "
414+ ++ [%e const_str_expr(name)]
415+ ++ " is missing"
416+ ],
417+ );
418+ }
419+ },
420+ )
421+ | Fr_fragment_spread (key, loc, name) => {
422+ let loc = conv_loc(loc);
423+ (
410424 Labelled (key),
411- switch %expr (
412- Js . Dict . get(value, [% e const_str_expr(key)])
413- ) {
414- | Some (value ) =>
425+ {
426+ let %expr value = Js.Json.object_(value);
415427 %e
416- generate_decoder(config, inner)
417- | None =>
418- if %e (can_be_absent_as_field(inner)) {
419- % expr
420- None ;
421- } else {
422- make_error_raiser(
423- [% expr
424- "Field "
425- ++ [% e const_str_expr(key)]
426- ++ " on type "
427- ++ [% e const_str_expr(name)]
428- ++ " is missing"
429- ],
430- );
431- }
428+ generate_solo_fragment_spread (loc , name );
432429 },
433- )
434- | Fr_fragment_spread (key , loc , name ) => {
435- let loc = conv_loc(loc);
436- (
437- Labelled (key),
438- {
439- let %expr value = Js.Json.object_(value);
440- %e
441- generate_solo_fragment_spread (loc , name );
442- },
443- );
444- },
445- ),
446- [
447- (
448- Nolabel ,
449- Ast_helper . Exp . construct(
450- {txt: Longident . Lident ("()" ), loc: Location . none},
451- None ,
452- ),
430+ );
431+ },
432+ ),
433+ [
434+ (
435+ Nolabel ,
436+ Ast_helper . Exp . construct(
437+ {txt: Longident . Lident ("()" ), loc: Location . none},
438+ None ,
453439 ),
454- ] ,
455- ) ,
440+ ) ,
441+ ] ,
456442 ),
457- )
458- }
459- ) ;
443+ ),
444+ ) ;
445+ } ;
460446}
461447and generate_poly_variant_selection_set = (config, loc, name, fields) => {
462448 let rec generator_loop =
0 commit comments