Repository navigation
Apollo ClientをTanStack Query + graphql-requestへ置き換えてAPI通信レイヤーを軽量化 - #6210
Conversation
|
Warning Review limit reached
More reviews will be available in 1 minute and 31 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughApollo Client から React Query + graphql-request へのデータ取得層を置き換え、新しいカスタムフック useGraphQLQuery(宣言的)と useLazyGraphQLQuery(命令的)を実装し、全 UI コンポーネント・カスタムフック・スクリーンのクエリ呼び出しを統一的に移行。 ChangesApollo Client から React Query への GraphQL データ取得層の全面置き換え
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/StationSearchModal.tsx (1)
200-204:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
useEffect内でのAlert.alert直接呼び出しを避けてください。StrictMode 環境では
useEffectが開発時に再実行されるため、エラー発生時にアラートが重複表示される可能性があります。コーディングガイドラインに従い、src/utils/alertPresentation.tsの共有 guard を使用してください。コーディングガイドラインより: "Do not call
Alert.alertdirectly fromuseEffector from async functions launched byuseEffectunder StrictMode; use the shared alert presentation guard insrc/utils/alertPresentation.ts"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/StationSearchModal.tsx` around lines 200 - 204, The useEffect currently calls Alert.alert directly (see useEffect block referencing fetchStationsByNameError and fetchStationsNearbyError); replace this direct call with the shared alert presentation guard exported from src/utils/alertPresentation.ts by importing the guard and invoking it when fetchStationsByNameError or fetchStationsNearbyError becomes truthy, so alerts are presented via the centralized guard instead of Alert.alert inside useEffect.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/components/StationSearchModal.tsx`:
- Around line 200-204: The useEffect currently calls Alert.alert directly (see
useEffect block referencing fetchStationsByNameError and
fetchStationsNearbyError); replace this direct call with the shared alert
presentation guard exported from src/utils/alertPresentation.ts by importing the
guard and invoking it when fetchStationsByNameError or fetchStationsNearbyError
becomes truthy, so alerts are presented via the centralized guard instead of
Alert.alert inside useEffect.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d1e6d18d-f800-4c15-bd3c-b3c3a0fe7b7d
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (21)
package.jsonsrc/components/StationSearchModal.tsxsrc/hooks/index.tssrc/hooks/useDeepLink.test.tsxsrc/hooks/useDeepLink.tssrc/hooks/useFetchNearbyStation.test.tsxsrc/hooks/useFetchNearbyStation.tssrc/hooks/useGraphQLQuery.test.tsxsrc/hooks/useGraphQLQuery.tssrc/hooks/useLazyGraphQLQuery.test.tsxsrc/hooks/useLazyGraphQLQuery.tssrc/hooks/useLineSelection.test.tsxsrc/hooks/useLineSelection.tssrc/hooks/useTrainTypeModal.test.tsxsrc/hooks/useTrainTypeModal.tssrc/hooks/useTrainTypeStations.tssrc/index.tsxsrc/lib/gql.tssrc/lib/graphql/queries.tssrc/screens/Main.tsxsrc/screens/RouteSearchScreen.tsx
概要
API通信に使用していたApollo Clientを廃止し、TanStack Query + graphql-request構成へ移行しました。本アプリのGraphQL利用はクエリのみ(mutation/subscription/正規化キャッシュ未使用、
typePoliciesでkeyFields: falseを全指定済み)でApolloがオーバースペックだったため、より軽量な構成に置き換えています。変更の種類
変更内容
@apollo/clientを削除し、@tanstack/react-query/graphql-request@^6/graphql-tagを追加src/lib/gql.ts:GraphQLClient+QueryClientに置き換え。staleTime: InfinityでApolloのcache-firstと等価なキャッシュ挙動を維持。フック外からの命令的フェッチ用にgqlClient.query()互換ファサードを維持(usePresetCarouselData/useStationsCacheとそのテストは無変更)useLazyGraphQLQuery/useGraphQLQuery: ApolloのuseLazyQuery/useQueryと同一のAPI形状をTanStack Query上で再現(executeはエラー時もrejectせず{ data, error }で解決する契約を維持)。ユニットテスト9件を追加RouteSearchScreenのcache.evict()+cache.gc()はqueryClient.removeQueries()に置換src/lib/graphql/queries.ts:gqlタグのimport元をgraphql-tagに変更(入れ子フラグメントの重複定義排除のため)src/index.tsx:ApolloProvider→QueryClientProvider@apollo/client/react→~/hooks/useLazyGraphQLQueryに変更(テストロジックは無変更)リグレッションリスクと対策
staleTime: Infinity)で挙動を維持useLazyQueryのexecute契約(エラー時にrejectしない)を維持し、呼び出し側のエラーハンドリングへの影響を排除テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ることローカルで
npm run lint && npm test && npm run typecheckを実行し、177スイート・1872テスト全件パスを確認済み。関連Issue
スクリーンショット(任意)
UI変更なし
https://claude.ai/code/session_01GdNc8HmHmMaYZk5G62hUah
Generated by Claude Code
Summary by CodeRabbit