Skip to content

Commit

Permalink
Merge pull request #103 from anmonteiro/patch-1
Browse files Browse the repository at this point in the history
Pass operation name in graphql_lwt
  • Loading branch information
rrosenzweig authored Aug 8, 2018
2 parents de110fb + 236cf65 commit c7c8d31
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions graphql-lwt/src/graphql_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ module Server = struct
| Ok _ as ok -> ok
| Error err -> Error (`String err)

let execute_query ctx schema variables query =
let execute_query ctx schema variables operation_name query =
let open Lwt_result in
Lwt.return @@ json_err @@ Graphql_parser.parse query >>= fun doc ->
Schema.execute schema ctx ~variables doc
Schema.execute schema ctx ~variables ?operation_name doc

let execute_request ctx schema req body =
Cohttp_lwt.Body.to_string body >>= fun body' ->
Lwt_io.printf "Body: %s\n" body';
let json = Yojson.Basic.from_string body' in
let query = Yojson.Basic.(json |> Util.member "query" |> Util.to_string) in
let variables = try Yojson.Basic.Util.(json |> member "variables" |> to_assoc) with _ -> [] in
let operation_name =
try Some Yojson.Basic.Util.(json |> member "operationName" |> to_string)
with _ -> None
in
Lwt_io.printf "Query: %s\n" query;
let result = execute_query ctx schema (variables :> (string * Graphql_parser.const_value) list) query in
let result = execute_query ctx schema (variables :> (string * Graphql_parser.const_value) list) operation_name query in
result >>= function
| Ok data ->
let body = Yojson.Basic.to_string data in
Expand Down

0 comments on commit c7c8d31

Please sign in to comment.