{"id":14976137,"url":"https://github.com/zth/graphql-generate-flow-schema-assets","last_synced_at":"2026-03-09T10:01:12.509Z","repository":{"id":53545794,"uuid":"113778859","full_name":"zth/graphql-generate-flow-schema-assets","owner":"zth","description":"Generate Flow assets from GraphQL schema.","archived":false,"fork":false,"pushed_at":"2021-03-25T04:17:23.000Z","size":43,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-06T17:50:28.881Z","etag":null,"topics":["flow","flowtype","graphql","graphql-schema","javascript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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}},"created_at":"2017-12-10T19:55:08.000Z","updated_at":"2022-04-21T23:52:21.000Z","dependencies_parsed_at":"2022-08-26T13:41:00.295Z","dependency_job_id":null,"html_url":"https://github.com/zth/graphql-generate-flow-schema-assets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zth/graphql-generate-flow-schema-assets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fgraphql-generate-flow-schema-assets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fgraphql-generate-flow-schema-assets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fgraphql-generate-flow-schema-assets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fgraphql-generate-flow-schema-assets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zth","download_url":"https://codeload.github.com/zth/graphql-generate-flow-schema-assets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fgraphql-generate-flow-schema-assets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30290888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["flow","flowtype","graphql","graphql-schema","javascript"],"created_at":"2024-09-24T13:53:22.583Z","updated_at":"2026-03-09T10:01:12.472Z","avatar_url":"https://github.com/zth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-generate-flow-schema-assets\nA small lib to help generating various Flow assets from a GraphQL schema.\nIt currently finds all `enum` and `object` types in your schema and outputs them both as JS constants and as Flow types.\n\nThe point of this lib is to:\n\n1. Make you rely on auto generated code straight from the source of truth (the schema),\ninstead of hard coding constants into your code.\n1. Help type check and by that make your code resilient to change by providing a fully typed \nextraction of assets from your GraphQL schema. \n\nIdeally, this lib is used in combination with saving your schema from your backend.\nExample in `package.json`:\n\n```\n\"scripts\": {\n  ...\n  \"graphql:save-schema\": \"some-script-to-save-your-schema \u0026\u0026 npm run graphql:generate-assets\",\n  \"graphql:generate-assets\": \"graphql-generate-flow-schema-assets -s path/to/schema.json --enums --object-types --enum-file-path ./src/constants/enums.js --object-types-file-path ./src/constants/object-types.js\"\n  ...\n```\n\nThis way, your code always relies auto generated code 100% in sync with your backend.\nIf something changes in a incompatible way in the schema, Flow will tell you since the generated types will change.\n\n## Installation\n```\nnpm install -g graphql-generate-flow-schema-assets\n```\n\n## Usage\nAll options can be seen by running:\n```\ngraphql-generate-flow-schema-assets -h\n```\n### Generating Enum constants\n```\ngraphql-generate-flow-schema-assets -s path/to/schema.json --enums\n```\nThis will generate a file containing all enums from your GraphQL schema\nboth as types and as actual objects. This means that instead of doing:\n\n```\nif (user.status === 'Active') {\n...\n```\n\nYou can do:\n\n```javascript\nimport { UserStatuses } from '../path/to/enums.js';\n\nif (user.status === UserStatuses.Active) {\n...\n```\n\n...meaning it'll be type checked, auto completed by your editor/IDE, and all \nof that good stuff.\n\n### Generating Object types\n```\ngraphql-generate-flow-schema-assets -s path/to/schema.json --object-types\n```\nThis will generate a file containing all object types from your GraphQL schema\nboth as types and as properties on one root object. This means that instead of doing:\n\n```javascript\nif (userOrSomeOtherType.__typename === 'User') {\n  ...\n```\n\nYou can do:\n\n```javascript\nimport { ObjectTypes } from '../path/to/object-types.js';\n\nif (userOrSomeOtherType.__typename === ObjectTypes.User) {\n  ...\n```\n\n...meaning it'll be type checked, auto completed by your editor/IDE, and all \nof that good stuff.\n\n### Extra\nThe lib `flow-enum-validator` is well suited to work with the enum output of this library to help validate unknown strings to enums. An example:\n\n```javascript\n// @flow\nimport { UserStatuses } from '../path/to/enums.js';\nimport { createEnumValidator } from 'flow-enum-validator';\n\n// This will return a function that takes a string and returns if it's a valid part of the UserStatuses enum object, or void if it's not\nconst validateUserStatus = createEnumValidator(UserStatuses);\n\nconst userStatus = validateUserStatus(someRandomStringHere);\n/**\n * Say UserStatuses is an object that looks like this: { Active: 'Active', Inactive: 'Inactive' }\n * Flow will now have refined userStatus to 'Active' | 'Inactive' | null | void.\n */\n\nif (userStatus) {\n  // userStatus is now 'Active' | 'Inactive'\n}\n\n```\n\nCheck out `flow-enum-validator` [here for more info and examples](https://github.com/zth/flow-enum-validator).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fgraphql-generate-flow-schema-assets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzth%2Fgraphql-generate-flow-schema-assets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fgraphql-generate-flow-schema-assets/lists"}