Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created February 6, 2020 22:35
Show Gist options
  • Save fakenickels/1e6a651593e9e2a119d1eea8fa3efae3 to your computer and use it in GitHub Desktop.
Save fakenickels/1e6a651593e9e2a119d1eea8fa3efae3 to your computer and use it in GitHub Desktop.
open Graphql_lwt;
type role =
| Admin
| User;
type user = {
id: int,
name: string,
role,
};
let users = [
{id: 1, name: "Alice", role: Admin},
{id: 2, name: "Bob", role: User},
];
let role: Schema.typ(unit, option(role)) =
Schema.(
enum(
"role",
~doc="The role of a user",
~values=[
enum_value("USER", ~value=User),
enum_value("ADMIN", ~value=Admin),
],
)
);
let user =
Schema.(
obj("user", ~doc="A user in the system", ~fields=_ =>
[
field(
"id",
~doc="Unique user identifier",
~typ=non_null(int),
~args=Arg.[],
~resolve=(_info, p) =>
p.id
),
field(
"name", ~typ=non_null(string), ~args=Arg.[], ~resolve=(_info, p) =>
p.name
),
field("role", ~typ=non_null(role), ~args=Arg.[], ~resolve=(_info, p) =>
p.role
),
]
)
);
let schema =
Schema.(
schema([
field(
"users",
~doc="A user",
~typ=non_null(list(non_null(user))),
~args=Arg.[],
~resolve=(_info, ()) =>
[{id: 1, name: "Bob", role: Admin}]
),
])
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment