Skip to content

plugin-relay: More generalized global ID codec support. #1579

Description

@cometkim

Currently the @pothos/plugin-relay is a bit opinionated on the global id format and is difficult to customize.

The type definition has following constraints:

  • Type names are stored as strings.
  • IDs are serialized as string/number/bigint.
  • No extra keys other than typename and id are included.

I have production code that doesn't meet the above constraints.

const typeRegistry = new WeakMap<DocumentSchema, number>();
typeRegistry.set(UserSchema, 1);

export function encodeGlobalIDv2(Schema: DocumentSchema, Id: DocumentId) {
  const CODEC_VERSION = 2;
  const repr = {
    v: CODEC_VERSION,
    t: typeRegistry.get(Schema),
    i: Id.buffer, // ArrayBuffer
  };
  const buf = CBOR.encode(repr);
  return buf.toString('base64url');
}

As you can see, the global ID encodings may not use a string representation internally at all, or may have different metadata keys.

I couldn't find a way to use the built-in types in @pothos/plugin-relay.

It would be nice to improve the interface to make it more generic, allowing the use of any custom global ID codecs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions