Skip to content

Commit

Permalink
Return errors as JSON object
Browse files Browse the repository at this point in the history
  • Loading branch information
ozanmakes committed Jul 7, 2018
1 parent bd121b2 commit dddb241
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphql-lwt/src/graphql_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Server = struct
C.Server.respond_string ~status:`OK ~body ()
| Error err ->
let body = Yojson.Basic.to_string err in
C.Server.respond_error ~body ()
C.Server.respond_string ~status:`Internal_server_error ~body ()

let mk_callback mk_context schema conn (req : Cohttp.Request.t) body =
Lwt_io.printf "Req: %s\n" req.resource;
Expand Down
14 changes: 14 additions & 0 deletions graphql-lwt/test/lwt_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ let schema = Graphql_lwt.Schema.(schema [
~typ:(non_null int)
~args:Arg.[]
~resolve:(fun () () -> Lwt.return (Ok 42))
;
io_field "io_error"
~typ:string
~args:Arg.[]
~resolve:(fun () () -> Lwt.return (Error "error"))
]
)

Expand All @@ -45,6 +50,15 @@ let suite = [
]
])
);
("error reporting", `Quick, fun () ->
test_query schema () "{ io_error }" (`Assoc [
"data", `Assoc [
"io_error", `Null
];
"errors", `List [
`Assoc [ "message", `String "error" ]
]
]))
]

let () = Alcotest.run "graphql-server" ["lwt", suite]

0 comments on commit dddb241

Please sign in to comment.