Here's an example of how we we gqtx today to be able to avoid duplicating code between implementers of the ILedger interface.
const LedgerInterface = t.interfaceType<Raw.Ledger>({
name: 'ILedger',
fields: () => [
t.abstractField({name: 'id', type: t.String}),
t.abstractField({name: 'name', type: t.String}),
t.abstractField({name: 'users', type: t.List(LedgerUserType)}),
],
})
/**
* Way to share implemention of the LedgerInterface
* Need to figure out how to share the `users` implementation between books and tabs
* Or perhaps better to not differentiate at all?
*/
function makeLedgerSubtype(options: {
name: string
isTypeOf: (l: Raw.Ledger) => boolean
fields: () => Array<Field<GQLContext, Raw.Ledger, unknown, {}>>
}) {
return t.objectType<Raw.Ledger>({
name: options.name,
interfaces: [LedgerInterface],
isTypeOf: options.isTypeOf,
fields: () => [
t.field({name: 'id', type: t.String}),
t.field({name: 'name', type: StringType}),
t.field({
name: 'users',
type: t.List(UserType),
// resolve: (ledger, __, ctx) =>
}),
...options.fields(),
],
})
}
It's a bit cumbersome, but still better than duplicating the code. In an ideal world the LedgerInterface would just be able to contain the implementation details (optionally) and avoid needing to duplicate all together.
Here's an example of how we we gqtx today to be able to avoid duplicating code between implementers of the
ILedger
interface.It's a bit cumbersome, but still better than duplicating the code. In an ideal world the LedgerInterface would just be able to contain the implementation details (optionally) and avoid needing to duplicate all together.