Resolvers
To write resolvers create resolvers.ts
file. Resolvers arguments are
type-safe. To make type-safe responses please use satisfies
and import
generated response types from models.js
resolvers.ts
import { BeerOrm } from '@/src/ormBeersFile.js';
import { createResolvers } from '@/src/axolotl.js'
const Beer = BeerOrm();
export default createResolvers({
Query: {
beers: () => Beer.list(),
},
Mutation: {
// the type of input and args is inferred 🥳 from createResolvers function
addBeer: (input, args) => {
return Beer.create(args.beer);
},
deleteBeer: (input, args) => {
return Beer.remove(args);
},
updateBeer: (input, args) => {
return Beer.update(args._id, args.beer);
},
},
});