-
Using the plugin Given the graphql schema type Cart
@key(fields: "id")
@extends
{
lineItemsStock: [LineItemStock!]! @external
id: ID!
canCheckout: Boolean! @requires(fields: "lineItemsStock { stock sku }")
}
When writing the pothos builder that generates the above schema export const CartRef = builder.externalRef<Selection<{ id: string }>, Cart>('Cart', builder.selection('id')).implement({
externalFields: (fieldBuilder) => ({
lineItemsStock: fieldBuilder.field({
type: [LineItemStockRef],
}),
}),
fields: (fieldBuilder) => ({
id: fieldBuilder.exposeID('id'),
canCheckout: fieldBuilder.boolean({
requires: builder.selection<{ lineItemsStock: LineItemStock }>('lineItemsStock { stock sku }'),
// types for requires on a list field are incorrect
resolve: (cart) => canCheckout(cart as unknown as Cart & { lineItemsStock: LineItemStock[] }),
}),
}),
}) the The correct type for |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You are providing the type in your requires section, so it should be: export const CartRef = builder.externalRef<Selection<{ id: string }>, Cart>('Cart', builder.selection('id')).implement({
externalFields: (fieldBuilder) => ({
lineItemsStock: fieldBuilder.field({
type: [LineItemStockRef],
}),
}),
fields: (fieldBuilder) => ({
id: fieldBuilder.exposeID('id'),
canCheckout: fieldBuilder.boolean({
requires: builder.selection<{ lineItemsStock: LineItemStock[] }>('lineItemsStock { stock sku }'),
resolve: (cart) => canCheckout(cart),
}),
}),
}) |
Beta Was this translation helpful? Give feedback.
-
I just kicked off a release with a fix for this. It should work correctly after upgrading. Let me know if you have any other issues |
Beta Was this translation helpful? Give feedback.
I just kicked off a release with a fix for this. It should work correctly after upgrading. Let me know if you have any other issues