import { objectType } from '@nexus/schema'; import { NodeType } from '../../../schema/node'; import { UserType } from '../../user/schema'; import { authenticateQuery } from '../../../../src/schema/authenticate-query'; import { ForbiddenError } from 'apollo-server-micro'; import { IngredientListType } from '../../ingredient/schema'; // The Recipe Definition export const RecipeType = objectType({ name: 'Recipe', definition(t) { t.implements('Node'); t.string('title', { description: 'Title of the recipe', nullable: true }); t.string('instructions', { description: 'Instructions of the recipe' }); t.field('ingredientList', { type: 'IngredientList' }); t.field('owner', { type: 'User', resolve: async (root, args, context, info) => { const { abilities } = authenticateQuery(context); const owner = await root .getOwner() .accessibleBy(abilities) .exec(); if (owner == null) { throw new ForbiddenError('Unable to view User'); } return owner; }, }); }, }); // ** exports export { recipeQF } from './fetch-recipe'; export { recipesQF } from './fetch-recipes'; export { createRecipeMF, CreateRecipeIputType } from './create-recipe'; export { updateRecipeMF, UpdateRecipeIputType } from './update-recipe'; export { deleteRecipeMF, DeleteRecipeIputType } from './delete-recipe';