mirror of
https://github.com/aantron/dream.git
synced 2025-11-12 00:05:46 -05:00
38 lines
730 B
OCaml
38 lines
730 B
OCaml
type user = {
|
|
id : int;
|
|
name : string;
|
|
}
|
|
|
|
let hardcoded_users = [
|
|
{id = 1; name = "alice"};
|
|
{id = 2; name = "bob"};
|
|
]
|
|
|
|
let user =
|
|
Graphql_lwt.Schema.(obj "user"
|
|
~doc:"A user"
|
|
~fields:(fun _ -> [
|
|
field "id"
|
|
~doc:"User id"
|
|
~typ:(non_null int)
|
|
~args:Arg.[]
|
|
~resolve:(fun _ user -> user.id);
|
|
field "name"
|
|
~doc:"User name"
|
|
~typ:(non_null string)
|
|
~args:Arg.[]
|
|
~resolve:(fun _ user -> user.name);
|
|
]))
|
|
|
|
let schema =
|
|
Graphql_lwt.Schema.(schema [
|
|
field "users"
|
|
~typ:(non_null (list (non_null user)))
|
|
~args:Arg.[]
|
|
~resolve:(fun _ () -> hardcoded_users);
|
|
])
|
|
|
|
let () =
|
|
Dream.run
|
|
(Dream.graphql Lwt.return schema)
|