Skip to content

Instantly share code, notes, and snippets.

View kenmori's full-sized avatar

KenjiMorita kenmori

View GitHub Profile
@kenmori
kenmori / ReactHooksTips.md
Last active May 17, 2019 00:42
ReactHooks Tips

ReactHooksTips

callback

//from
const callback = useCallback((state)=>{ setState(state.value)}, [state.value])
@kenmori
kenmori / jest x apolloでmock query data を使っているのだけれど dataのところでundefinedになってテストで落ちる.md
Last active May 8, 2019 15:16
jest x apolloでmock query data を使っているのだけれど dataのところでundefinedになってテストで落ちる

TypeError: Cannot destructure property [PropertyName] of 'undefined' or 'null'.

jest x apolloでmock query data を使っているのだけれど dataのところでundefinedになってテストで落ちる

not jest setting,

@kenmori
kenmori / apollo-clientがQeuryやMutationをしたさいのcacheの作られ方を理解する.md
Last active October 9, 2020 09:46
apollo-clientがQeuryやMutationした際のlocal cacheの作られ方を理解する

apollo-clientがQeuryやMutationした際のlocal cacheの作られ方を理解する

こちらはHow to update the Apollo Client’s cache after a mutationを意訳し、さらにapolloClientの仕様書での文章を読んでりかいしたことです。 英語読める方はリンク先、仕様書を見ることをお勧めします


@kenmori
kenmori / writeToStore.ts?f824:194 Missing field [FIELD_NAME] in.md
Last active May 5, 2019 11:26
これが出たら[apollo x react] writeToStore.ts?f824:194 Missing field [FIELD_NAME] in

writeToStore.ts?f824:194 Missing field [FIELD_NAME] in

subscribeでupdate関数内で更新したオブジェクトを返すとcache側で識別できないのでエラーになっている

Observable.js?a7b2:63 Uncaught Error: Store error: the application attempted to write an object with no provided typename but the store already contains an object with typename of MessageConnection for the object of id $ROOT_QUERY.messages({"messageThreadId":"04140231-6c68-4396-bd5b-58c5fece5e51"}). The selectionSet that was trying to be written is:

@kenmori
kenmori / InMemoryCache.md
Last active December 5, 2020 20:31
Apollo-client のInMemoryCache(キャッシュ)と向きあう

Apollo-clientのInMemoryCache(キャッシュ)と向きあう

InMeoryCacheのオブジェクトの様子

addTypename: true
@kenmori
kenmori / jspra.md
Last active April 30, 2019 02:29
JavaScript問題集に問題を追加しました。

JavaScript問題集に問題を追加しました。

JavaScript問題集

問370

aという変数に{}かkeyがあるかどうか評価してください

@kenmori
kenmori / Invariant Violation: Could not find "client" in the context or passed in as a prop.md
Last active April 27, 2019 23:59
解決: Solution 「Invariant Violation: Could not find "client" in the context or passed in as a prop」

When you test for .test file using apollo. often occure below error.

Invariant Violation: Could not find "client" in the context or passed in as a prop. Wrap the root component in an <ApolloProv
ider>, or pass an ApolloClient instance in via props.

       5 | it('renders without crashing', () => {
@kenmori
kenmori / mutation_and_refetch_query.md
Last active April 25, 2019 08:28
[react-apollo] mutationを叩いたら他の場所にあるqueryをrefetchして値を同期させる

add fetchPolicy="cache-and-network"を追加

const Noti = () => (
  <Query query={unreadMessagesQuery} fetchPolicy="cache-and-network">
    {({ data, loading, error }) => {
      if(loading) return <LoadView />;
 if (error) return ;
@kenmori
kenmori / How to call any number of multiple mutations after getting query result.md
Last active April 24, 2019 00:01
[react-apollo]How to call any number of multiple mutations after getting query result (not Batch)

react-apolloでclient.queryの結果をみて、そのidの数だけmutationを実行する

In the message read function, I had to update "already read" for the number of messages that have been made in the message details page. Certainly I want to be able to use Batch and update at one time, I can't find the way right now, so I feel better

メッセージの既読機能で、メッセージ画面詳細で任意の数だけ行われているメッセージ分の「既読」更新をしなければならなかった. 確かにBatchをつかって、1回で更新できたらいいけど

@kenmori
kenmori / ApolloClient(GraphQL) x React Hooks で出た可愛いエラーErrorへの対応.md
Last active August 9, 2019 15:49
【エラー解決】ApolloClient(GraphQL) x React Hooks x apollo-react x apollo-react-hooks x graphql

【エラー解決】ApolloClient(GraphQL) x React Hooks x apollo-react x apollo-react-hooks x graphql

1.Uncaught Error: Could not find "client" in the context or passed in as a prop. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via props.

contextの中にclientが見つからないか、propsとして渡ってきてません。ApolloProviderの中の root componentをラップするか、propsをとおしてApolloClient instanceを渡してください

For Example, you see like this below code. It's occur Error.