{"id":18334141,"url":"https://github.com/villesau/nexus-to-pothos-codemod","last_synced_at":"2025-04-06T03:34:52.761Z","repository":{"id":65126660,"uuid":"582339877","full_name":"villesau/nexus-to-pothos-codemod","owner":"villesau","description":"Transforms Nexus code to Pothos","archived":false,"fork":false,"pushed_at":"2023-01-05T10:53:43.000Z","size":178,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T06:38:35.276Z","etag":null,"topics":["codemod","codemods","graphql","nexus","pothos","transform"],"latest_commit_sha":null,"homepage":"","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/villesau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-26T14:09:32.000Z","updated_at":"2025-01-07T18:50:59.000Z","dependencies_parsed_at":"2023-02-04T02:04:19.489Z","dependency_job_id":null,"html_url":"https://github.com/villesau/nexus-to-pothos-codemod","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/villesau%2Fnexus-to-pothos-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/villesau%2Fnexus-to-pothos-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/villesau%2Fnexus-to-pothos-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/villesau%2Fnexus-to-pothos-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/villesau","download_url":"https://codeload.github.com/villesau/nexus-to-pothos-codemod/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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":["codemod","codemods","graphql","nexus","pothos","transform"],"created_at":"2024-11-05T19:47:01.099Z","updated_at":"2025-04-06T03:34:52.749Z","avatar_url":"https://github.com/villesau.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nexus to Pothos codemod\n\n[![npm version](https://badge.fury.io/js/nexus-to-pothos-codemod.svg)](https://www.npmjs.com/package/nexus-to-pothos-codemod)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/villesau/nexus-to-pothos-codemod/blob/master/README.md#Contributing)\n\nThis is a codemod to migrate from [Nexus](https://nexusjs.org/) to [Pothos](https://pothos-graphql.dev/)\n\nThis aims to transform all the nexus types, queries and mutations to Pothos equivalents. Please note that\nthe codemod is by no means complete. You still need some manual adjustments. Below is a list of known missing features.\n\nYou can check out the [`__textfixtures__`](https://github.com/villesau/nexus-to-pothos-codemod/tree/master/__testfixtures__) folder to see full list of supported transformations.\n\n## Why should I migrate to use Pothos?\n\n- Pothos has superior type safety\n- Pothos does not require you to generate types which makes type feedback much much faster\n- Pothos is actively maintained\n\n## Install\n\n```bash\n$ yarn global add nexus-to-pothos-codemod\n```\n\nor\n\n```bash\n$ npm install -g nexus-to-pothos-codemod\n```\n\n## Usage\n\n```bash\n$ nexus-to-pothos-codemod ./**/*.ts --ignore-pattern=\"**/node_modules/**\" --parser=ts\n```\n\nThe CLI is the same as in [jscodeshift](https://github.com/facebook/jscodeshift)\nexcept you can omit the transform file.\n\nAlternatively, you can run the codemod using jscodeshift as follows:\n\n```bash\n$ yarn global add jscodeshift\n$ yarn add nexus-to-pothos-codemod\n$ jscodeshift -t node_modules/nexus-to-pothos-codemod/transform.ts --ignore-pattern=\"**/node_modules/**\" ./**/*.js  --parser=ts\n```\n\n## Migrating the codebase\n\nThe codemod might not be 100% accurate. You will need to do some manual adjustments. Might be good to compare\nthe generated GraphQL schema with the old one to see if there are any differences.\n\n## What is missing?\n\n- automatic import updates\n- it assumes some conventions such as `async nodes((_, args, ctx) {}` instead of `nodes: async ((_, args, ctx) =\u003e {}` which causes exceptions\n- does not understand computed fields such as:\n\n    ```\n  export const Object = objectType({\n    name: 'Object',\n    definition(t) {\n      objectFields.forEach(objectField =\u003e t.string(objectField));\n    }\n  });\n  ```\n- might fail on complex types\n- `unionType` not transformed\n- `scalarType` not transformed\n- lists not handled properly always, `[]` needs to be mostly added manually\n- args of `connnectionField` not transformed preoperly\n- `authScope` in connectionField and some nested fields not transformed properly\n- all caveats might not be discovered since the codemod is developed against single codebase with it's own conventions\n\nParts that causes exceptions can be commented out and fixed manually. Rest are fairly easy to compare to the old schema.\nBe extra careful with the `authScope`.\n\nAn example builder config:\n\n```ts\nimport SchemaBuilder from '@pothos/core';\nimport RelayPlugin from '@pothos/plugin-relay';\nimport ScopeAuthPlugin from '@pothos/plugin-scope-auth';\nimport { GraphQLJSONObject } from 'graphql-type-json';\n\nexport const builder = new SchemaBuilder\u003c{\n  Context: {};\n  DefaultEdgesNullability: false;\n  DefaultNodeNullability: false;\n  Scalars: {\n    ID: {\n      Output: number | string;\n      Input: string;\n    };\n    JSONObject: {\n      Output: object;\n      Input: object;\n    };\n  };\n}\u003e({\n  plugins: [ScopeAuthPlugin, RelayPlugin],\n  authScopes: context =\u003e ({}),\n  scopeAuthOptions: {\n    unauthorizedError: () =\u003e new Error(`Not authorized`)\n  },\n  relayOptions: {\n    clientMutationId: 'omit',\n    cursorType: 'ID',\n    edgesFieldOptions: {\n      nullable: false\n    },\n    nodeFieldOptions: {\n      nullable: false\n    }\n  }\n});\n\nbuilder.queryType();\nbuilder.mutationType();\nbuilder.addScalarType('JSONObject', GraphQLJSONObject, {});\n```\n\n## Contributing\n\nContributions are more than welcome! Some useful tools for developing this are https://astexplorer.net/ and your editors builtin debugger.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvillesau%2Fnexus-to-pothos-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvillesau%2Fnexus-to-pothos-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvillesau%2Fnexus-to-pothos-codemod/lists"}