-
Hello. I am encountering From doc: Option 2 https://pothos-graphql.dev/docs/guide/enums interface MyStatusRoot {
status: any;
}
const StatusTypesOptions = ['active', 'inactive'] as const;
const StatusTypes = builder.enumType(StatusTypes, {
values: StatusTypesOptions,
});
export const MyStatus = builder.objectRef<MyStatusRoot>('MyStatus');
builder.objectType(MyStatus, {
fields: t => ({
status: t.field('status', {
type: StatusTypes, // also tried this as string
nullable: false,
description: 'The user status.',
resolve: (root: any) => root.status
}),
}),
}); Attempt 2: Following answer here - #445 (comment) interface MyStatusRoot {
status: any;
}
export enum StatusTypes {
active,
inactive,
}
builder.enumType(StatusTypes, {
name: 'StatusTypes',
});
export const MyStatus = builder.objectRef<MyStatusRoot>('MyStatus');
builder.objectType(MyStatus, {
fields: t => ({
status: t.field('status', {
type: StatusTypes, // also tried this as string
nullable: false,
description: 'The user status.',
resolve: (root: any) => StatusTypes[root.status as keyof typeof StatusTypes],
}),
}),
}); Full error
|
Beta Was this translation helpful? Give feedback.
Answered by
arvi
Jun 27, 2025
Replies: 1 comment
-
Solved this for some reason using spread operator. // in schema objects dir
const StatusTypesOptions = ['active', 'inactive'] as const;
export const StatusTypes = builder.enumType('StatusTypes', {
values: StatusTypesOptions,
});
export const MyStatus = builder.objectRef<MyStatusRoot>('MyStatus');
builder.objectType(MyStatus, {
fields: t => ({
...addStatusField({
t,
fieldType: StatusTypes,
}),
}),
});
// in schema objects field utils dir
export const addStatusField = ({
t,
fieldType,
fieldName = 'status',
}: AddStatusFieldArgs) => {
// .... other logic here
return {
[fieldName]: t.field({
type: fieldType,
resolve: root => root.status,
}),
};
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
arvi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved this for some reason using spread operator.