{"id":19011595,"url":"https://github.com/graphql-editor/transform-graphql","last_synced_at":"2025-04-22T23:27:17.166Z","repository":{"id":57379021,"uuid":"305388256","full_name":"graphql-editor/transform-graphql","owner":"graphql-editor","description":"⚙️ Transformer function to transform GraphQL Directives. Create model CRUD directive for example","archived":false,"fork":false,"pushed_at":"2022-02-21T16:04:43.000Z","size":173,"stargazers_count":24,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-17T16:03:18.172Z","etag":null,"topics":["amplify","dgraph","graphback","graphql","transform","transformer"],"latest_commit_sha":null,"homepage":"https://graphqleditor.com","language":"TypeScript","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/graphql-editor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-19T13:11:38.000Z","updated_at":"2024-03-27T13:21:24.000Z","dependencies_parsed_at":"2022-09-05T08:10:27.234Z","dependency_job_id":null,"html_url":"https://github.com/graphql-editor/transform-graphql","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/graphql-editor%2Ftransform-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-editor%2Ftransform-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-editor%2Ftransform-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-editor%2Ftransform-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphql-editor","download_url":"https://codeload.github.com/graphql-editor/transform-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250339376,"owners_count":21414350,"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":["amplify","dgraph","graphback","graphql","transform","transformer"],"created_at":"2024-11-08T19:14:57.887Z","updated_at":"2025-04-22T23:27:17.151Z","avatar_url":"https://github.com/graphql-editor.png","language":"TypeScript","readme":"# Transform GraphQL\n\n[![npm](https://img.shields.io/npm/v/transform-graphql.svg?style=flat-square)](https://www.npmjs.com/package/transform-graphql)  [![npm downloads](https://img.shields.io/npm/dt/transform-graphql.svg?style=flat-square)](https://www.npmjs.com/package/transform-graphql)\n[![npm downloads](https://img.shields.io/github/workflow/status/graphql-editor/transform-graphql/release.svg?style=flat-square)](https://www.npmjs.com/package/transform-graphql)\n\n\nWe use GraphQL transformers. Examples are Graphback, Dgraph, AWS Amplify. This library provides function that given any GraphQL schema creates new GraphQL schemas basing on transformer functions.\n\n## Installation\n\n```sh\nnpm i transform-graphql\n```\n\n## How it works\n\nProvide original schema with your transformer directives and an array of transformer functions defined by `TransformerDef` type\n\n```ts\n\nimport { TransformGraphQLSchema } from 'transform-graphql';\n\nconst transformedSchema = TransformGraphQLSchema({ \n    schema: inputSchema, \n    transformers: [transformerCRUD] \n});\n\n\n```\n\nThis short example simply shows what transform GraphQL is about:\n\nGiven the schema:\n```graphql\ntype Post @model{\n    name: String!\n    content: String!\n    createdAt: String!\n}\n\ntype Query{\n    version:String\n}\ntype Mutation{\n    version:String\n}\n\ndirective @model on OBJECT\n```\nwhere model is our actual transformer\n\nWe expect schema to be transformed into\n\n```graphql\n\ndirective @model on OBJECT\n\ninput CreatePost{\n    name: String!\n    content: String!\n    createdAt: String!\n}\n\ninput DetailsPost{\n    id: String!\n}\n\ntype Mutation{\n    version: String\n    post: PostMutation\n}\n\ntype Post @model{\n    name: String!\n    content: String!\n    createdAt: String!\n}\n\ntype PostMutation{\n    create(\n            post: CreatePost\n    ): String!\n    update(\n            post: UpdatePost\n            details: DetailsPost\n    ): String!\n    remove(\n            details: DetailsPost\n    ): String!\n}\n\ntype PostQuery{\n    list: [Post!]!\n    getByDetails(\n            details: DetailsPost\n    ): Post\n}\n\ntype Query{\n    version: String\n    post: PostQuery\n}\ninput UpdatePost{\n    name: String!\n    content: String!\n    createdAt: String!\n}\nschema{\n    query: Query,\n    mutation: Mutation\n}\n```\n\nAnd the transformer code should look like this\n\n```ts\nconst inputSchema = `\ntype Post @model{\n    name: String!\n    content: String!\n    createdAt: String!\n}\n\ntype Query{\n    version:String\n}\ntype Mutation{\n    version:String\n}`\nconst transformerCRUD: TransformerDef = {\n  transformer: ({ field, operations }) =\u003e {\n    if (!field.args) {\n      throw new Error('Model can be used only for types');\n    }\n    if (!operations.query) {\n      throw new Error('Query type required');\n    }\n    if (!operations.mutation) {\n      throw new Error('Query type required');\n    }\n    return `\n      input Create${field.name}{\n          ${TreeToGraphQL.parse({ nodes: field.args })}\n      }\n      input Update${field.name}{\n          ${TreeToGraphQL.parse({ nodes: field.args })}\n      }\n      input Details${field.name}{\n          id: String!\n      }\n      type ${field.name}Query{\n          list: [${field.name}!]!\n          getByDetails(details: Details${field.name}): ${field.name}\n      }\n      type ${field.name}Mutation{\n          create( ${field.name[0].toLowerCase() + field.name.slice(1)}: Create${field.name} ): String!\n          update( ${field.name[0].toLowerCase() + field.name.slice(1)}: Update${field.name}, details: Details${\n      field.name\n    } ): String!\n          remove( details: Details${field.name} ): String!\n      }\n      extend type ${operations.query.name}{\n          ${field.name[0].toLowerCase() + field.name.slice(1)}: ${field.name}Query\n      }\n      extend type ${operations.mutation.name}{\n          ${field.name[0].toLowerCase() + field.name.slice(1)}: ${field.name}Mutation\n      }\n      `;\n  },\n  directiveName: 'model',\n};\nconst transformedSchema = TransformGraphQLSchema({ schema: GraphQLTransform, transformers: [transformerCRUD] });\n//transfomed schema should look like in the example\n\n```\n\n## Roadmap\n\n- provide CLI\n- provide examples\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-editor%2Ftransform-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphql-editor%2Ftransform-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-editor%2Ftransform-graphql/lists"}