{"id":19164203,"url":"https://github.com/coobaha/graphql-to-reason","last_synced_at":"2025-05-07T11:23:26.850Z","repository":{"id":48201225,"uuid":"153912203","full_name":"Coobaha/graphql-to-reason","owner":"Coobaha","description":"transform GraphQL schema to ReasonML types","archived":false,"fork":false,"pushed_at":"2023-07-11T21:27:50.000Z","size":399,"stargazers_count":52,"open_issues_count":5,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T15:48:34.525Z","etag":null,"topics":["graphql","reasonml"],"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/Coobaha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-10-20T14:09:50.000Z","updated_at":"2021-09-10T11:32:08.000Z","dependencies_parsed_at":"2024-01-10T19:11:01.808Z","dependency_job_id":null,"html_url":"https://github.com/Coobaha/graphql-to-reason","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fgraphql-to-reason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fgraphql-to-reason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fgraphql-to-reason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fgraphql-to-reason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Coobaha","download_url":"https://codeload.github.com/Coobaha/graphql-to-reason/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252866568,"owners_count":21816491,"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","reasonml"],"created_at":"2024-11-09T09:19:27.267Z","updated_at":"2025-05-07T11:23:26.829Z","avatar_url":"https://github.com/Coobaha.png","language":"Reason","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-to-reason\n\nThis tool will transform existing GraphQL schema to ReasonML types to be used on server side.\n\n[![Build Status](https://travis-ci.org/Coobaha/graphql-to-reason.svg?branch=master)](https://travis-ci.org/Coobaha/graphql-to-reason)\n[![npm](https://img.shields.io/npm/v/graphql-to-reason.svg)](https://www.npmjs.com/package/graphql-to-reason)\n\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n    \u003cb\u003eExamples\u003c/b\u003e\n  \u003c/summary\u003e\n  \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"/examples/basic\"\u003eBasic example\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/details\u003e\n\n\u003cp\u003e\u003c/p\u003e\n\n## Installation\nFirst, add this package as a dependency to your package.json\n```\nyarn add --dev graphql-to-reason\n# or, if you use npm:\nnpm install -D graphql-to-reason\n```\n\n`graphql-to-reason` requires json variant (aka introspection query) of `schema.graphql`.\n\n`schema.json` can be generated with `npx graphql-to-reason-schema schema.graphql schema.json`.\n\nIntegration with Bucklescript can be done via [generators](https://bucklescript.github.io/docs/en/build-advanced#customize-rules-generators-support)\n\na) With already introspected schema\n```json\n{\n  \"generators\": [\n    {\n      \"name\": \"generate-schematypes\",\n      \"command\": \"npx graphql-to-reason $in $out\"\n    }\n  ],\n  \"sources\": [\n    {\n      \"dir\": \"src\",\n      \"generators\": [\n        {\n          \"name\": \"generate-schematypes\",\n          \"edge\": [ \"SchemaTypes_builder.re\", \":\", \"schema.json\"]\n        }\n      ]\n    }\n  ]\n}\n```\n\nb) From `.graphql`\n\n```json\n{\n  \"generators\": [\n    {\n      \"name\": \"generate-schematypes\",\n      \"command\": \"npx graphql-to-reason-schema $in $in.json  \u0026\u0026 npx graphql-to-reason $in.json $out\"\n    }\n  ],\n  \"sources\": [\n    {\n      \"dir\": \"src\",\n      \"generators\": [\n        {\n          \"name\": \"generate-schematypes\",\n          \"edge\": [\"SchemaTypes_builder.re\", \"schema.graphql.json\", \":\", \"schema.graphql\"]\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Examples\n\nSimple `schema.graphql`\n\n```graphql\nscalar Click\n\ntype Query {\n    clicks: Click!\n}\n\ntype Mutation {\n    click(payload: String!): Click!\n}\n```\n\nNext we generate ReasonML code from it:\n`npx graphql-to-reason schema.json SchemaTypes_builder.re`\n\nIt will output `SchemaTypes_builder.re` to use it in other modules:\n```reason\ninclude SchemaTypes_builder.MakeSchema({\n  /* we need to configure our server types:\n      - all scalar types\n      - resolver type\n      - custom directive resolver type  */\n  module Scalars = {\n    type click = int;\n  };\n\n  /* args - our arguments object\n     fieldType - original field type\n     result - resoved value (for example Js.Nullable.t(fieldType)) */\n  type resolver('args, 'fieldType, 'result) =\n    (\n      unit,\n      'args,\n      /*context args depend on your graphql setup*/\n      ServerContext.t,\n      ServerContext.ResolveInfo.t,\n      ServerContext.FieldInfo.t('fieldType)\n    ) =\u003e\n    Js.Promise.t('result);\n  type directiveResolver('payload);\n});\n\n\nmodule Clicks = {\n  let count = ref(0);\n  /* No need to explicitly type resolver, it will infer correct type later */\n  let resolver = (_node, _args, _context, _resolveInfo, _fieldInfo) =\u003e\n    Js.Promise.make((~resolve, ~reject) =\u003e {\n      count := count^ + 1;\n      resolve(count^);\n    });\n};\n\n\n/* Clicks.resolver now infers SchemaTypes.Mutation.clicksCount type */\nlet mutationResolvers =\n  SchemaTypes.Mutation.t(~clicks=Clicks.resolver, ());\n\nlet resolvers = SchemaTypes.t(~mutation, ());\n\ncreateMyGraphqlServer(resolvers);\n```\n\n\n### Developing\n\nInstall [esy](https://github.com/esy/esy):\n\n`npm install -g esy@latest`\n\nInstall dependencies:\n\n`make install`\n\nTo build executables:\n\n`make build`\n\nTo run tests:\n\n`make test` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoobaha%2Fgraphql-to-reason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoobaha%2Fgraphql-to-reason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoobaha%2Fgraphql-to-reason/lists"}