Created
June 9, 2022 09:52
-
-
Save socialwell-demos/71ecf460f5ed1bd07d129636453c10d0 to your computer and use it in GitHub Desktop.
Keystone Virtual Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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