Skip to content

Instantly share code, notes, and snippets.

@seandearnaley
seandearnaley / useRemoveCategory.ts
Created February 18, 2020 05:56
old version of useRemoveCategory
import { ApolloError, FetchResult } from '@apollo/client';
import {
GetCategoriesDocument,
useRemoveCategoryMutation,
CategoryPartsFragment,
RemoveCategoryMutation,
} from '../../generated/graphql';
// NOTE: the rationale for using a custom hook is for the cache update,
@seandearnaley
seandearnaley / useRemoveCard.ts
Last active February 18, 2020 10:13
old useRemoveCard
import { ApolloError, FetchResult } from '@apollo/client';
import {
useRemoveCardMutation,
RemoveCardMutation,
GetCategoryWithCardsDocument,
GetCategoryWithCardsQuery,
} from '../../generated/graphql';
import { buildPageInfo } from './__utils';
@seandearnaley
seandearnaley / afterIdLimitPaginatedFieldPolicy.ts
Created February 18, 2020 10:01
afterIdLimitPaginatedFieldPolicy
function afterIdLimitPaginatedFieldPolicy<T>() {
return {
merge(existing: T[], incoming: T[], { args, readField }): T[] {
...
},
read(existing: T[], { args, readField }): T[] {
...
},
};
}
@seandearnaley
seandearnaley / useRemoveCard.ts
Last active February 22, 2020 02:03
useRemoveCard.ts beta 37
import {
ApolloError,
FetchResult,
Reference,
ApolloCache,
} from '@apollo/client';
import {
useRemoveCardMutation,
RemoveCardMutation,
@seandearnaley
seandearnaley / useRemoveCategory.ts
Last active February 22, 2020 18:40
useRemoveCategory.ts beta 36
const removeCategory = (id: string) =>
removeCategoryMutation({
variables: {
id,
},
update: cache => {
cache.modify('ROOT_QUERY', {
categories(categories: Reference[], { readField }) {
return categories.filter(
category => id !== readField('id', category),
@seandearnaley
seandearnaley / codegen.yml
Created February 19, 2020 04:21
codegen.yml
overwrite: true
schema: "http://localhost:4000/graphql"
documents: src/**/*.graphql
generates:
src/generated/graphql.ts:
hooks:
afterOneFileWrite:
- prettier --write
plugins:
- "typescript"
@seandearnaley
seandearnaley / codegen.yml
Last active April 3, 2020 02:31
codegen.yml
overwrite: true
schema: "http://localhost:4000/graphql"
documents: src/**/*.graphql
generates:
src/generated/graphql.ts:
hooks:
afterOneFileWrite:
- prettier --write
plugins:
- "typescript"
@seandearnaley
seandearnaley / index.ts
Last active April 3, 2020 06:55
Example Index.ts
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import {
ApolloClient,
ApolloProvider,
HttpLink,
InMemoryCache,
} from '@apollo/client';
@seandearnaley
seandearnaley / cuckoosCallingBook.js
Created February 19, 2020 05:40
identify example
const cuckoosCallingBook = {
__typename: 'Book',
isbn: '031648637X',
title: "The Cuckoo's Calling",
author: {
__typename: 'Author',
name: 'Robert Galbraith',
},
};
@seandearnaley
seandearnaley / GetCategoryNode.graphql
Created February 19, 2020 06:17
GetCategoryNode.graphql
# import CardParts from "CardParts.graphql";
# import CategoryParts from "CategoryParts.graphql";
query GetCategoryNode(
$id: ID!
$first: Int
$last: Int
$after: String
$before: String
$orderByColumn: String