I am using nexus.js to build GraphQL schema. To define a type, we use ObjectDefinitionBlock. I define the object type as following:
export const Choice = objectType({
name: 'Choice',
definition(t) {
t.id('id', { resolve: (x) => x.id.toString() });
t.string('value');
t.int('order');
}
});
The t is a ObjectDefinitionBlock that allows to define object fields. The x.id is a bigint type and is serialized as a built-in GraphQL scalar type - ID. Since, I use bigint for all my database Ids, I have to always add a resolver to convert bigint to string. I want to augment this t so that I can write:
t.bigId('id');
Note that I don't want to define a new scalar. Just need to write a facade over the scalar ID to avoid writing repetitive definition for resolve function. Is there any way to achieve this?