Created
October 13, 2019 06:31
-
-
Save sync/87cd91839da07aa9b046f62c4b465b90 to your computer and use it in GitHub Desktop.
GraphQL Reason server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Lwt.Infix; | |
open Graphql_lwt; | |
type role = | |
| User | |
| Admin; | |
type user = { | |
id: int, | |
name: string, | |
role, | |
friends: list(user), | |
}; | |
let rec alice = {id: 1, name: "Alice", role: Admin, friends: [bob]} | |
and bob = {id: 2, name: "Bob", role: User, friends: [alice]}; | |
let users = [alice, bob]; | |
let role = | |
Schema.( | |
enum( | |
"role", | |
~values=[ | |
enum_value("USER", ~value=User, ~doc="A regular user"), | |
enum_value("ADMIN", ~value=Admin, ~doc="An admin user"), | |
], | |
) | |
); | |
let user = | |
Schema.( | |
obj("user", ~fields=user => | |
[ | |
field("id", ~args=Arg.[], ~typ=non_null(int), ~resolve=(_, p) => | |
p.id | |
), | |
field("name", ~args=Arg.[], ~typ=non_null(string), ~resolve=(_, p) => | |
p.name | |
), | |
field("role", ~args=Arg.[], ~typ=non_null(role), ~resolve=(_, p) => | |
p.role | |
), | |
field( | |
"friends", | |
~args=Arg.[], | |
~typ=list(non_null(user)), | |
~resolve=(_, p) => | |
Some(p.friends) | |
), | |
] | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment