{"action":"created","issue":{"url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/126","repository_url":"https://api.github.com/repos/andreas/ocaml-graphql-server","labels_url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/126/comments","events_url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/126/events","html_url":"https://github.com/andreas/ocaml-graphql-server/pull/126","id":367887503,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIxMTkyNTc1","number":126,"title":"New package: graphql-cohttp","user":{"login":"andreas","id":2518,"node_id":"MDQ6VXNlcjI1MTg=","avatar_url":"https://avatars3.githubusercontent.com/u/2518?v=4","gravatar_id":"","url":"https://api.github.com/users/andreas","html_url":"https://github.com/andreas","followers_url":"https://api.github.com/users/andreas/followers","following_url":"https://api.github.com/users/andreas/following{/other_user}","gists_url":"https://api.github.com/users/andreas/gists{/gist_id}","starred_url":"https://api.github.com/users/andreas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreas/subscriptions","organizations_url":"https://api.github.com/users/andreas/orgs","repos_url":"https://api.github.com/users/andreas/repos","events_url":"https://api.github.com/users/andreas/events{/privacy}","received_events_url":"https://api.github.com/users/andreas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-08T17:35:49Z","updated_at":"2018-11-01T21:08:12Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/andreas/ocaml-graphql-server/pulls/126","html_url":"https://github.com/andreas/ocaml-graphql-server/pull/126","diff_url":"https://github.com/andreas/ocaml-graphql-server/pull/126.diff","patch_url":"https://github.com/andreas/ocaml-graphql-server/pull/126.patch"},"body":"This PR introduces a new package `graphql-cohttp` for serving GraphQL requests via HTTP using the `cohttp` library. It generalises the server previously found in `Graphql_lwt.Server` to be IO-agnostic, and thus should work with both `Async`, `Lwt` with Unix, and `Lwt` with Mirage.\r\n\r\nThe PR is an alternative approach compared to #116. However, rather than try to encompass running a HTTP server, which makes the required functor arguments very complex, it only provides two capabilities:\r\n\r\n1) Executing a single HTTP request against a GraphQL schema.\r\n2) Constructing a callback function to be used with a `Cohttp_async.Server`, `Cohttp_lwt_unix.Server` or `Cohttp_mirage.Server`.\r\n\r\nThis has the benefits that the functor argument is quite simple, and it exposes some primitives that compose better with other libraries (e.g. `opium`, see #121).\r\n\r\nRunning a server is slightly more code than with `Graphql_lwt.Server`, but I think the above benefits outweigh this drawback. Example:\r\n\r\n```ocaml\r\nmodule HttpBody = struct\r\n  include Cohttp_lwt.Body\r\n\r\n  type +'a io = 'a Lwt.t\r\n  type 'a stream = 'a Lwt_stream.t * (unit -> unit)\r\n\r\n  let of_stream (stream, _) = Cohttp_lwt.Body.of_stream stream\r\nend\r\n\r\nmodule Graphql_cohttp_lwt = Graphql_cohttp.Make (Graphql_lwt.Schema) (HttpBody)\r\n\r\nlet callback = Graphql_cohttp_lwt.make_callback (fun _req -> ()) schema in\r\nlet server = Cohttp_lwt_unix.Server.make ~callback () in\r\nlet mode = `TCP (`Port 8080) in\r\nCohttp_lwt_unix.Server.create ~mode server\r\n```\r\n(if `Lwt_stream.t` supported closing, this would be much simpler -- the `Async` case is very simple)\r\n\r\nA couple of other changes have been lumped into this PR:\r\n\r\n- The `Stream` module has been moved into `Io`, since `Stream` depends on `Io` anyway.\r\n- `Graphql_intf.Schema` exposes the provided `Io` module.\r\n- The HTTP server supports returning subscription results as Server-Sent Events."},"comment":{"url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/comments/435187787","html_url":"https://github.com/andreas/ocaml-graphql-server/pull/126#issuecomment-435187787","issue_url":"https://api.github.com/repos/andreas/ocaml-graphql-server/issues/126","id":435187787,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTE4Nzc4Nw==","user":{"login":"zshipko","id":332534,"node_id":"MDQ6VXNlcjMzMjUzNA==","avatar_url":"https://avatars1.githubusercontent.com/u/332534?v=4","gravatar_id":"","url":"https://api.github.com/users/zshipko","html_url":"https://github.com/zshipko","followers_url":"https://api.github.com/users/zshipko/followers","following_url":"https://api.github.com/users/zshipko/following{/other_user}","gists_url":"https://api.github.com/users/zshipko/gists{/gist_id}","starred_url":"https://api.github.com/users/zshipko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zshipko/subscriptions","organizations_url":"https://api.github.com/users/zshipko/orgs","repos_url":"https://api.github.com/users/zshipko/repos","events_url":"https://api.github.com/users/zshipko/events{/privacy}","received_events_url":"https://api.github.com/users/zshipko/received_events","type":"User","site_admin":false},"created_at":"2018-11-01T21:08:12Z","updated_at":"2018-11-01T21:08:12Z","author_association":"NONE","body":"Yeah, that would work. It is *slightly* inconvenient to have to handle this but definitely much better than re-implementing the server!\r\n\r\nI’m happy to update my branch to test it out once these changes are made to `graphql-cohttp`."}}
{"actor":{"display_login":"zshipko"}}