fieldResolver
In LIVON, fieldResolver is implemented with fieldOperation.
Use fieldOperation for type-safe field-level resolvers that depend on an entity schema.
import {fieldOperation, object, string} from '@livon/schema';
const User = object({
name: 'User',
shape: {
id: string(),
name: string(),
},
});
const GreetingOutput = string();
const userGreetingResolver = fieldOperation({
dependsOn: User,
output: GreetingOutput,
exec: async (entity) => `Hello ${entity.name}`,
});
Key points:
dependsOncan be a schema or a shapeoutputis optional but recommended for strict typingapi.typeis required whenfieldOperationsare used
dependsOn, input, and output can use any value schema from this section.
API schemas (api) are not valid as field resolver schemas.
Parameters
dependsOn(Schema | Shape, required): source entity schema (or shape shorthand).input(Schema | Shape, optional): resolver input schema.output(Schema, optional): resolver output schema.exec((dependsOn, ctx) => result | Promise<result>or(dependsOn, input, ctx) => result | Promise<result>, required): resolver function.doc(SchemaDoc, optional): field resolver metadata.
Chain API
fieldOperationdoes not expose schema chain methods (return type: FieldOperation<...>, notSchema<T>).- Use value schemas for
dependsOn,input, andoutputwhere chain methods are available.