diff --git a/src/bucklescript/output_bucklescript_module.re b/src/bucklescript/output_bucklescript_module.re index 7b8a5054..2e6dee2a 100644 --- a/src/bucklescript/output_bucklescript_module.re +++ b/src/bucklescript/output_bucklescript_module.re @@ -178,8 +178,9 @@ let generate_default_operation = Result_structure.res_loc(res_structure), variable_defs, ); - let (make_fn, make_with_variables_fn, make_variables_fn) = + let (make_fn, make_with_variables_fn, make_variables_fn, definition_tuple) = Output_bucklescript_unifier.make_make_fun(config, variable_defs); + List.concat([ make_printed_query(config, [Graphql_ast.Operation(operation)]), List.concat([ @@ -205,6 +206,7 @@ let generate_default_operation = [%stri let make = [%e make_fn]], [%stri let makeWithVariables = [%e make_with_variables_fn]], [%stri let makeVariables = [%e make_variables_fn]], + [%stri let definition = [%e definition_tuple]], ], ]), ret_type_magic, diff --git a/src/bucklescript/output_bucklescript_unifier.re b/src/bucklescript/output_bucklescript_unifier.re index 40e72419..30321f6a 100644 --- a/src/bucklescript/output_bucklescript_unifier.re +++ b/src/bucklescript/output_bucklescript_unifier.re @@ -13,6 +13,14 @@ open Output_bucklescript_utils; exception Unimplemented(string); let make_make_fun = (config, variable_defs) => { + let make_tuple = (loc, variables, compose) => [%expr + ( + parse, + ppx_printed_query, + graphql_ppx_use_json_variables_fn => [%e compose], + ) + ]; + let make_make_triple = (loc, variables) => Ast_helper.Exp.extension( ~loc, @@ -126,10 +134,17 @@ let make_make_fun = (config, variable_defs) => { ) ]; + let user_function = + make_labelled_function( + item, + [%expr graphql_ppx_use_json_variables_fn([%e variable_ctor_body])], + ); + ( make_labelled_function(item, make_make_triple(loc, variable_ctor_body)), make_object_function(item, make_make_triple(loc, variable_ctor_body)), make_labelled_function(item, variable_ctor_body), + make_tuple(loc, variable_ctor_body, user_function), ); | None => ( [%expr @@ -143,6 +158,7 @@ let make_make_fun = (config, variable_defs) => { ) ], [%expr (() => [%e [%expr Js.Json.null]])], + [%expr [%e make_tuple(Location.none, [%expr Js.Json.null], [%expr 0])]], ) }; };