{"id":13726721,"url":"https://github.com/lessp/revery-graphql-hooks","last_synced_at":"2025-04-13T13:26:38.876Z","repository":{"id":74854625,"uuid":"217762735","full_name":"lessp/revery-graphql-hooks","owner":"lessp","description":"A library for easy handling of GraphQL with hooks for Revery","archived":false,"fork":false,"pushed_at":"2020-08-19T13:58:11.000Z","size":542,"stargazers_count":31,"open_issues_count":3,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T08:53:45.606Z","etag":null,"topics":["graphql","hooks","revery"],"latest_commit_sha":null,"homepage":"","language":"Reason","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lessp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-26T20:02:05.000Z","updated_at":"2024-06-04T21:28:47.000Z","dependencies_parsed_at":"2023-03-29T18:48:15.919Z","dependency_job_id":null,"html_url":"https://github.com/lessp/revery-graphql-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Frevery-graphql-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Frevery-graphql-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Frevery-graphql-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Frevery-graphql-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lessp","download_url":"https://codeload.github.com/lessp/revery-graphql-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248719567,"owners_count":21150759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","hooks","revery"],"created_at":"2024-08-03T01:03:17.660Z","updated_at":"2025-04-13T13:26:38.851Z","avatar_url":"https://github.com/lessp.png","language":"Reason","funding_links":[],"categories":["Reason"],"sub_categories":[],"readme":"# Revery GraphQL Hooks\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\nA library for easy handling of GraphQL within Revery using [graphql_ppx](https://github.com/reasonml-community/graphql_ppx).\n\n## Table of Contents\n\n1. [Getting started](#getting-started)\n2. [Syntax](#syntax)\n3. [Todo](#todo)\n4. [Contributing](#contributing)\n5. [License](#license)\n\n## Getting started\n\n### Installing\n\nIn your `package.json/esy.json` add:\n\n```json\n\"dependencies\": {\n  ...\n  \"graphql_ppx\": \"reasonml-community/graphql_ppx:esy.json\",\n  \"revery\": \"revery-ui/revery\",\n  \"revery-graphql-hooks\": \"lessp/revery-graphql-hooks\",\n}\n```\n\nYou will also need to copy anu `resolutions` in [example.json](example.json) except for `revery-graphql-hooks`.\n\nthen in your `dune`-file:\n\n```lisp\n(preprocess\n  (pps\n    graphql_ppx ;; + any other preprocessors (e.g. brisk-reconciler.ppx) for Revery\n  ))\n(libraries\n  ;; any other libraries\n  Revery Revery.lwt revery-graphql-hooks)\n```\n\n### Setup\n\nCreate a file, lets name it `Graphql.re` for easy access.\n\nIn this file we'll specify some settings for our HTTP-calls.\n\n(If you'd like to try out the example below, you can use: `https://hello-graphql-api.lessp.now.sh/api`)\n\n```ocaml\nmodule Config = {\n  let baseUrl = \"https://your_graphql_api_endpoint.com/\";\n  let headers = [];\n};\n\ninclude ReveryGraphqlHooks.Make(Config);\n```\n\n**NOTE:** For Revery to handle Promises we need to start the event loop. Add the following line, prior to calling `UI.start`.\n\n```ocaml\nlet _startEventLoop = Revery_Lwt.startEventLoop();\n```\n\nThat's all, we can now make some queries!\n\n## Syntax\n\n### Query\n\n```ocaml\nmodule HelloQueryConfig = [%graphql\n  {|\n    query Hello {\n      hello {\n        name\n      }\n    }\n  |}\n];\n\nlet%component make = () =\u003e {\n  let%hook status = Graphql.useQuery(HelloQueryConfig.definition, ());\n\n  let text = switch (status) {\n  | Idle =\u003e \"Idle\"\n  | Data(query) =\u003e query#hello#name\n  | Loading =\u003e \"Loading...\"\n  | Error =\u003e \"Error\"\n  };\n\n  \u003cText text /\u003e;\n};\n```\n\n### Mutation\n\n```ocaml\nmodule AddGreetingConfig = [%graphql\n  {|\n    mutation AddGreeting($greeting: String!) {\n      addGreeting(greeting: $greeting)\n    }\n  |}\n];\n\nlet%component make = () =\u003e {\n  let%hook (addGreetingMutation, status) =\n    Graphql.useMutation(AddGreetingConfig.definition, ());\n\n  let text =\n    switch (status) {\n    | Idle =\u003e \"Idle\"\n    | Data(query) =\u003e query#addGreeting\n    | Loading =\u003e \"Loading...\"\n    | Error =\u003e \"Error\"\n    };\n\n  \u003cCenter\u003e\n    \u003cButton\n      onClick={_ =\u003e\n        addGreeting(\n          ~variables=AddGreeting.makeVariables(~greeting=\"Cheers\", ()),\n          (),\n        )\n      }\n      title=\"Click to add\"\n    /\u003e\n    \u003cText text /\u003e\n  \u003c/Center\u003e;\n};\n```\n\n## ToDo\n\n- [x] Propagate updates to hooks with the same queries\n- [x] Simplify API by using `definition` from `graphql_ppx`\n- [ ] Cache\n\n## Contributing\n\nContributions are more than welcome! Start by cloning this repository. The runnable example is located in [examples/](examples/), the library itself is located in [src/](src/).\n\n```\n# to build the library\nesy\n\n# to run the examples\nesy '@example' start\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://lessp.dev/\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/17602389?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTom Ekander\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-lessp\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/lessp/revery-graphql-hooks/commits?author=lessp\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/lessp/revery-graphql-hooks/commits?author=lessp\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://twitter.com/rita_krutikova\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/5932274?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMargarita Krutikova\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-MargaretKrutikova\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/despairblue\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/927609?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDanny Martini\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-despairblue\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/lessp/revery-graphql-hooks/commits?author=despairblue\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessp%2Frevery-graphql-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flessp%2Frevery-graphql-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessp%2Frevery-graphql-hooks/lists"}