npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nexus-to-pothos-codemod

v0.3.2

Published

Codemod to migrate from Nexus to Pothos

Downloads

5

Readme

Nexus to Pothos codemod

npm version PRs Welcome

This is a codemod to migrate from Nexus to Pothos

This aims to transform all the nexus types, queries and mutations to Pothos equivalents. Please note that the codemod is by no means complete. You still need some manual adjustments. Below is a list of known missing features.

You can check out the __textfixtures__ folder to see full list of supported transformations.

Why should I migrate to use Pothos?

  • Pothos has superior type safety
  • Pothos does not require you to generate types which makes type feedback much much faster
  • Pothos is actively maintained

Install

$ yarn global add nexus-to-pothos-codemod

or

$ npm install -g nexus-to-pothos-codemod

Usage

$ nexus-to-pothos-codemod ./**/*.ts --ignore-pattern="**/node_modules/**" --parser=ts

The CLI is the same as in jscodeshift except you can omit the transform file.

Alternatively, you can run the codemod using jscodeshift as follows:

$ yarn global add jscodeshift
$ yarn add nexus-to-pothos-codemod
$ jscodeshift -t node_modules/nexus-to-pothos-codemod/transform.ts --ignore-pattern="**/node_modules/**" ./**/*.js  --parser=ts

Migrating the codebase

The codemod might not be 100% accurate. You will need to do some manual adjustments. Might be good to compare the generated GraphQL schema with the old one to see if there are any differences.

What is missing?

  • automatic import updates

  • it assumes some conventions such as async nodes((_, args, ctx) {} instead of nodes: async ((_, args, ctx) => {} which causes exceptions

  • does not understand computed fields such as:

    export const Object = objectType({
    name: 'Object',
    definition(t) {
      objectFields.forEach(objectField => t.string(objectField));
    }
    });
  • might fail on complex types

  • unionType not transformed

  • scalarType not transformed

  • lists not handled properly always, [] needs to be mostly added manually

  • args of connnectionField not transformed preoperly

  • authScope in connectionField and some nested fields not transformed properly

Parts that causes exceptions can be commented out and fixed manually. Rest are fairly easy to compare to the old schema. Be extra careful with the authScope.

An example builder config:

import SchemaBuilder from '@pothos/core';
import RelayPlugin from '@pothos/plugin-relay';
import ScopeAuthPlugin from '@pothos/plugin-scope-auth';
import { GraphQLJSONObject } from 'graphql-type-json';

export const builder = new SchemaBuilder<{
  Context: {};
  DefaultEdgesNullability: false;
  DefaultNodeNullability: false;
  Scalars: {
    ID: {
      Output: number | string;
      Input: string;
    };
    JSONObject: {
      Output: object;
      Input: object;
    };
  };
}>({
  plugins: [ScopeAuthPlugin, RelayPlugin],
  authScopes: context => ({}),
  scopeAuthOptions: {
    unauthorizedError: () => new Error(`Not authorized`)
  },
  relayOptions: {
    clientMutationId: 'omit',
    cursorType: 'ID',
    edgesFieldOptions: {
      nullable: false
    },
    nodeFieldOptions: {
      nullable: false
    }
  }
});

builder.queryType();
builder.mutationType();
builder.addScalarType('JSONObject', GraphQLJSONObject, {});

Contributing

Contributions are more than welcome! Some useful tools for developing this are https://astexplorer.net/ and your editors builtin debugger.