This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BaseModel, Model, StringField, ManyToMany } from 'warthog'; | |
| import { JoinTable, TreeChildren, TreeParent, Tree } from 'typeorm'; | |
| import { Card } from '../card/card.model'; | |
| @Model() | |
| @Tree("closure-table") | |
| export class Category extends BaseModel { | |
| @StringField({ nullable: true }) | |
| name?: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BaseModel, IntField, Model, StringField, ManyToMany } from 'warthog'; | |
| import { Category } from '../category/category.model'; | |
| @Model() | |
| export class Card extends BaseModel { | |
| @IntField({ nullable: true }) | |
| number?: number; | |
| @StringField({ nullable: true }) | |
| label?: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| Entity, | |
| Tree, | |
| Column, | |
| PrimaryGeneratedColumn, | |
| TreeChildren, | |
| TreeParent, | |
| ManyToMany, | |
| JoinTable, | |
| } from "typeorm"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from "typeorm"; | |
| import { Category } from "./Category"; | |
| @Entity() | |
| export class Card { | |
| @PrimaryGeneratedColumn("uuid") | |
| id: string; | |
| @Column() | |
| number: number; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3.6' | |
| services: | |
| postgres: | |
| image: postgres | |
| restart: always | |
| volumes: | |
| - ./db_data:/var/lib/postgresql/data | |
| ports: | |
| - 5432:5432 | |
| environment: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cache.modify(`Category:${categoryId}`, { | |
| cards(cards: Reference, { readField }) { | |
| const edges = readField<CardEdgeWithReference[]>('edges', cards).filter( | |
| edge => edge.node.__ref !== `Card:${cardId}`, | |
| ); | |
| let { totalCount } = readField<PageInfo>('pageInfo', cards); | |
| const pageInfo = buildPageInfo<Edge<Card>>(edges, --totalCount, 'Card'); // rebuild pageinfo | |
| return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const removeCategory = (id: string) => | |
| removeCategoryMutation({ | |
| variables: { | |
| id | |
| }, | |
| update: (cache, { data }) => { | |
| const { categories } = | |
| cache.readQuery({ | |
| query: GetCategoriesDocument, | |
| }) || {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const cache = new InMemoryCache({ | |
| ...possibleTypes, | |
| typePolicies: { | |
| Query: { | |
| fields: { | |
| card(existingData, { args, toReference }) { | |
| return ( | |
| existingData || toReference({ __typename: 'Card', id: args?.id }) | |
| ); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| update: cache => { | |
| cache.modify('ROOT_QUERY', { | |
| categories(categories: Reference[], { readField }) { | |
| return categories.filter( | |
| category => id !== readField('id', category), | |
| ); | |
| }, | |
| }); | |
| // evict this item from the in memory cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Node { | |
| id: ID! | |
| created: DateTime! | |
| updated: DateTime | |
| } | |
| type Card implements Node { | |
| id: ID! | |
| number: Int | |
| label: String |