import { objectType, enumType, interfaceType, unionType } from '@nexus/schema'; import { RecipeCollection, RecipeCollectionType, RecipeCollectionItem, } from '../collection-model'; import { RecipeFilterAttribute, RecipeFilterAction } from '../filters'; export const RecipeCollectionET = enumType({ name: 'RecipeCollectionType', description: 'All available ingredient measurement types', members: RecipeCollectionType, }); // The RecipeCollectionItem Definition export const RecipeCollectionItemOT = objectType({ name: 'RecipeCollectionItem', definition(t) { t.int('order', { description: 'The Oder within the collection', resolve: (root, args, ctx, info) => { const owner = root.parent() as RecipeCollection; return owner.nodes.indexOf(root); }, }); t.field('recipe', { type: 'Recipe' }); }, }); // The RecipeCollection Base Definition export const RecipeCollectionNT = interfaceType({ name: 'RecipeCollection', definition(t) { t.id('id'); t.string('name', { description: 'The Name of the collection', nullable: true, }); t.list.field('nodes', { type: 'RecipeCollectionItem' }); t.resolveType(r => { switch (r.kind) { case RecipeCollectionType.MANUAL: return RecipeCollectionOT.name; case RecipeCollectionType.SMART: return SmartRecipeCollectionOT.name; default: return RecipeCollectionOT.name; } }); }, }); // // Manual Collection // export const RecipeCollectionOT = objectType({ name: 'ManualRecipeCollection', definition(t) { t.implements('RecipeCollection'); }, }); // // Smart Collection // export const RecipeFilterAttributeET = enumType({ name: 'RecipeFilterAttribute', members: RecipeFilterAttribute, }); export const RecipeFilterActionET = enumType({ name: 'RecipeFilterAction', members: RecipeFilterAction, }); // The Filter Definition export const RecipeFilterOT = objectType({ name: 'RecipeFilter', definition(t) { t.implements('Node'); t.field('attribute', { type: RecipeFilterAttributeET }); t.field('action', { type: RecipeFilterActionET }); t.string('value', {}); }, }); // The RecipeCollection Definition export const SmartRecipeCollectionOT = objectType({ name: 'SmartRecipeCollection', definition(t) { t.implements('RecipeCollection'); t.list.field('nodes', { type: 'Recipe', resolve: async (root, args, ctx, info) => { return root.getRecipes(); }, }); t.list.field('filters', { type: 'RecipeFilter' }); }, }); // // exports // export { recipeCollectionQF } from './fetch-collection'; export { recipeCollectionsQF } from './fetch-collections'; export { createRecipeCollectionMF, RecpeFilterIT, CreateRecipeCollectionIT, } from './create-collection'; export { updateRecipeCollectionMF, UpdateRecipeCollectionIputType, } from './update-collection'; export { deleteRecipeCollectionMF, DeleteRecipeCollectionIputType, } from './delete-collection'; export { AddRecipesToCollectionInputType, AddRecipesToCollectionPayload, AddRecipesToCollectionMF, } from './add-recipes'; export { RemoveRecipesFromCollectionInput, RemoveRecipesFromCollectionPayload, RemoveRecipesFromCollectionMF, } from './remove-recipes'; export { UpdateRecipeInCollectionInput, UpdateRecipeInCollectionMF, } from './update-recipe'; export { AddFiltersToCollectionIT, AddFiltersToCollectionMF, } from './add-filters'; export { RemoveFiltersFromCollectionPayload, RemoveFiltersFromCollectionIT, RemoveFiltersFromCollectionMF, } from './remove-filters'; export { UpdateRecipeFilterIT, UpdateFilterInCollectionIT, UpdatefilterInCollectionMF, } from './update-filter';