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.
Currently the
@pothos/plugin-relayis a bit opinionated on the global id format and is difficult to customize.The type definition has following constraints:
string/number/bigint.typenameandidare included.I have production code that doesn't meet the above constraints.
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.