api
Use api({...}) to compose operation and subscription schemas into one API schema.
Minimal usage
import {api} from '@livon/schema';
const ApiSchema = api({
type: User,
operations: {
sendMessage,
},
subscriptions: {
onMessage,
},
fieldOperations: {
greeting: userGreetingResolver,
},
});
Runtime handoff
Pass the ApiSchema result directly to schemaModule(...):
import {runtime} from '@livon/runtime';
import {schemaModule} from '@livon/schema';
runtime(schemaModule(ApiSchema, {explain: true}));
No extra schema-module input adapter is required.
api({...}) input shape
type(optional): entity schema for field resolversoperations(optional): named map of operationssubscriptions(optional): named map of subscriptionsfieldOperations(optional): named map of field resolversdoc(optional): API-level docs metadata- operation shorthand keys (optional): operation entries can also be added directly on the root object
Parameters
type(Schema, optional): entity schema required whenfieldOperationsare used.operations(Record<string, operation(...)>, optional): operation map.subscriptions(Record<string, subscription(...) | Schema>, optional): subscription map.fieldOperations(Record<string, fieldOperation(...)>, optional): field resolvers.doc(SchemaDoc, optional): API-level metadata.- operation shorthand keys (
operation(...), optional): operation entries can also be defined directly on the root object.
Chain API
apidoes not expose schema chain methods (return type: Api<...>, notSchema<T>).- Use
operation,subscription, andfieldOperationto compose behavior.
Rules
- Every publish topic declared by an operation must exist in
subscriptions. typeis required whenfieldOperationsare defined.subscriptionsentries can besubscription({...})or schema shorthand payloads.