Skip to Page Navigation Skip to Page Navigation Skip to Content
Keystone 6
Blog Enterprise β†— Docs

Virtual

A virtual field represents a value which is computed at read time, rather than stored in the database. See the virtual fields guide for details on how to use virtual fields.

Options:

  • field (required): The GraphQL field that defines the type, resolver and arguments.
  • ui.query (default: '' ): Defines what the Admin UI should fetch from this field, it's interpolated into a query like this:
    query{
    item(where:{id:"..."}){
    field${ui.query}
    }
    }
    This is only needed when you your field returns a GraphQL type other than a scalar(String and etc.) or an enum or you need to provide arguments to the field.
import{ config, createSchema, g, list }from'@keystone-6/core';
import{ virtual }from'@keystone-6/core/fields';
exportdefaultconfig({
lists:{
SomeListName:list({
fields:{
someFieldName:virtual({
field: g.field({
type: g.String,
args:{ something: g.arg({ type: g.Int })},
resolve(item, args, context, info){
}
})
}),
/* ... */
},
}),
/* ... */
},
/* ... */
});

On this page

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /