pothos
pothos copied to clipboard
type parameters should accept "readonly" arrays
Some places where pothos accepts arrays in options (eg type for list types) don't work with readonly arrays. This can cause problems when using as const to create options compatible objects.
This would technically be a breaking change because all plugins that extend various interfaces accepting type parameters would need to be updated.
That means we can not use this pattern right?
type Payload = {
readonly items: Item[]
}
PaginatedDeliveries.implement({
description: "paginated deliveries",
fields: (t) => ({
items: t.expose("items", { type: [Item] }),
}),
});
no, this is would be unrelated.
As far as I can tell, that should work just fine
The thing that this is referring to would be something like:
const itemsType = [Item] as const;
const PaginatedDeliveries = builder.objectRef<Payload>('PaginatedDeliveries');
PaginatedDeliveries.implement({
description: 'paginated deliveries',
fields: (t) => ({
items: t.expose('items', { type: itemsType }),
}),
});
This shouldn't be something most people run into, but it can come up when trying to build helpers that generate fields for you.
thanks for the response, my case actually like this
export type PaginatedDeliveriesShape = {
readonly items: readonly Delivery[];
};
export const PaginatedDeliveries = graphql.objectRef<PaginatedDeliveriesShape>("PaginatedDeliveries");
PaginatedDeliveries.implement({
description: "paginated deliveries",
fields: (t) => ({
items: t.expose("items", { type: [delivery] }),
}),
});
then the eslint error thrown

I think it's related
Ah, I see, yeah. Similar issue, but not specifically what this issue was about. This should be easier to fix though
@minhlucvan this should be fixed in the latest release
This ended up being too big a breaking change to add into the 4.0 release, and hasn't really come up again, so closing this out for now