import { extendType } from '@nexus/schema'; import { ApolloError } from 'apollo-server-micro'; import { authenticateQuery } from '../../../schema/authenticate-query'; import { RecipeType } from './'; /** * Retrieve all recipes */ export const recipesQF = extendType({ type: 'Query', definition(t) { t.list.field('recipes', { type: 'Recipe', resolve: async (root, args, ctx, info) => { const { user, abilities } = authenticateQuery(ctx); // Resolve // fetch all recipes for the current user const recipes = user.getRecipes().catch(err => { throw new ApolloError('Error Retrieving Recipes', '400'); }); return recipes; }, }); }, });