{"id":13837972,"url":"https://github.com/zth/resgraph","last_synced_at":"2025-06-29T06:03:45.500Z","repository":{"id":150740149,"uuid":"623425409","full_name":"zth/resgraph","owner":"zth","description":"Build implementation-first GraphQL servers in ReScript","archived":false,"fork":false,"pushed_at":"2024-10-09T08:02:51.000Z","size":50744,"stargazers_count":59,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-29T06:02:20.606Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","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/zth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-04T10:51:32.000Z","updated_at":"2025-03-25T14:19:27.000Z","dependencies_parsed_at":"2023-04-14T00:09:42.477Z","dependency_job_id":"f17bbe32-c3fe-42af-b8c7-115985759ca3","html_url":"https://github.com/zth/resgraph","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/zth/resgraph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fresgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fresgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fresgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fresgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zth","download_url":"https://codeload.github.com/zth/resgraph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fresgraph/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262545022,"owners_count":23326654,"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":[],"created_at":"2024-08-04T15:01:32.186Z","updated_at":"2025-06-29T06:03:45.459Z","avatar_url":"https://github.com/zth.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"# ResGraph\n\nBuild implementation-first GraphQL servers in ReScript, with first class Relay integration.\n\n- [Check out the docs on getting started](https://zth.github.io/resgraph/docs/getting-started).\n- [Use this template to get started quickly](https://github.com/zth/resgraph-template).\n- [Install the dedicated VSCode extension](https://marketplace.visualstudio.com/items?itemName=GabrielNordeborn.vscode-resgraph)\n\n## What it looks like\n\nThis ReScript code:\n\n```rescript\n@gql.type\ntype query\n\n/** A timestamp. */\n@gql.scalar\ntype timestamp = float\n\n/** A thing with a name. */\n@gql.interface\ntype hasName = {@gql.field name: string}\n\n@gql.type\ntype user = {\n  ...hasName,\n  @gql.field /** When this user was created. */ createdAt: timestamp,\n  @gql.field @deprecated(\"Use 'name' instead\") fullName: string,\n}\n\n/** Format for text. */\n@gql.enum\ntype textFormat = Uppercase | Lowercase | Capitalized\n\n/** The user's initials, e.g 'Alice Smith' becomes 'AS'. */\n@gql.field\nlet initials = (user: user, ~format=Uppercase) =\u003e {\n  let initials = getInitials(user.name)\n\n  switch format {\n  | Uppercase | Capitalized =\u003e initials-\u003eString.toUpperCase\n  | Lowercase =\u003e initials-\u003eString.toLowerCase\n  }\n}\n\n/** The current time on the server. */\n@gql.field\nlet currentTime = (_: query): timestamp =\u003e {\n  Date.now()\n}\n\n/** The currently logged in user, if any. */\n@gql.field\nlet loggedInUser = async (_: query, ~ctx: ResGraphContext.context): option\u003cuser\u003e =\u003e {\n  switch ctx.currentUserId {\n  | None =\u003e None\n  | Some(userId) =\u003e await ctx.dataLoaders.userById.load(~userId)\n  }\n}\n```\n\nGenerates this schema:\n\n```graphql\ntype Query {\n  \"\"\"\n  The current time on the server.\n  \"\"\"\n  currentTime: Timestamp!\n\n  \"\"\"\n  The currently logged in user, if any.\n  \"\"\"\n  loggedInUser: User\n}\n\n\"\"\"\nA timestamp.\n\"\"\"\nscalar Timestamp\n\ntype User implements HasName {\n  \"\"\"\n  When this user was created.\n  \"\"\"\n  createdAt: Timestamp!\n  fullName: String! @deprecated(reason: \"Use 'name' instead\")\n\n  \"\"\"\n  The user's initials, e.g 'Alice Smith' becomes 'AS'.\n  \"\"\"\n  initials(format: TextFormat): String!\n  name: String!\n}\n\n\"\"\"\nA thing with a name.\n\"\"\"\ninterface HasName {\n  name: String!\n}\n\n\"\"\"\nFormat for text.\n\"\"\"\nenum TextFormat {\n  Uppercase\n  Lowercase\n  Capitalized\n}\n```\n\n[Check out the docs on getting started](https://zth.github.io/resgraph/docs/getting-started).\n\n## Introduction\n\nResGraph lets you build _implementation first_ GraphQL servers, where your types and code is the source of truth for the schema.\n\n## Features\n\n- [x] Query\n- [x] Mutations\n- [x] Subscriptions\n- [x] Context\n- [x] Object types\n- [x] Input types\n- [x] Interfaces\n- [x] Enums\n- [x] Unions\n- [x] Custom scalars (including custom serializers/parsers)\n- [ ] Directives\n- [x] Relay helpers (coming very soon)\n\n## Development notes\n\nThis is a heavy work-in-progess. The repo itself was originally forked from the ReScript editor tooling, which means that there's a ton of stuff lying around that aren't really used. This will be cleaned up later.\n\n### Local development\n\nFirst, set up OCaml.\n\n```bash\n# If you haven't created the switch, do it. OPAM(https://opam.ocaml.org)\nopam switch 4.14.0 # can also create local switch with opam switch create . 4.14.0\n\n# Install dev dependencies from OPAM\nopam install . --deps-only\n\n# For IDE support, install the OCaml language server\nopam install ocaml-lsp-server\n```\n\nThen, install JS dependencies:\n\n```bash\nnpm i\n```\n\nNow, you can build `ResGraph` and run its tests:\n\n```bash\n# You might need to run this twice the first time\nmake test\n```\n\nAccompanied with the tests is a simple test server that'll let you run GraphiQL to execute operations against the test schema. Start it by running:\n\n```bash\nnpm run watch-testapp\n```\n\nThis will start the test server and watch for changes so it's restarted with any change. You can now access GraphiQL at http://localhost:9898/graphql.\nThe test server will also dump an up to date `schema.graphql` on restart, so you'll be able to see how any changes you make affect the schema.\n\nFor the best experience, also run the ReScript compiler as a separate process:\n\n```bash\nnpx rescript build -w\n```\n\nThe workflow after this is setup is roughly:\n\n1. Make changes to the test schema (primarily located in `Schema.res`)\n2. Run `ResGraph` via `make test`\n3. Test the changes in GraphiQL, or see them in `schema.graphql`\n\n## High level overview of how ResGraph works\n\n1. You write your types and code in ReScript, and annotate them with attributes to expose them via GraphQL.\n2. ResGraph runs after the ReScript compiler has recompiled, and scans your project for all GraphQL-related things. It then extracts all relevant GraphQL things from the compiled type information.\n3. What it finds is then transformed into an actual `graphql-js` schema that you can run.\n\nResGraph is _fast_, because it's leveraging the standard ReScript tooling, and using OCaml.\n\n## Acknowledgements\n\nThis is a spiritual sibling project to [Grats](https://github.com/captbaritone/grats), from which this project derives most of its ideas, reimplemented in the ReScript ecosystem instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fresgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzth%2Fresgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fresgraph/lists"}