Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keystone Virtual Field
import { list, graphql } from '@keystone-6/core';
import {
text,
virtual,
} from '@keystone-6/core/fields';
export const Producer = list({
fields: {
firstName: text({ validation: { isRequired: true }, isFilterable: true }),
middleName: text({ isFilterable: true }),
lastName: text({ isFilterable: true }),
fullName: virtual({
field: graphql.field({
type: graphql.String,
resolve: (item: any) =>
`${item.firstName} ${item.middleName} ${item.lastName}`,
}),
}),
orgName: virtual({
field: graphql.field({
type: graphql.String,
async resolve(item, args, context) {
const { org } = await context.query.Producer.findOne({
where: { id: item.id.toString() },
query: 'org { orgName }',
});
return org && org.orgName;
},
}),
}),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment