Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
FlutterでGraphQL のuseQueryを使う
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
iganin
November 14, 2024
Technology
27
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FlutterでGraphQL のuseQueryを使う
Flutter Tokyo #5 登壇資料
iganin
November 14, 2024
More Decks by iganin
See All by iganin
FastMCP OAuth Proxy with Cognito
hironobuiga
3
340
Three-Legged OAuth in AgentCore Gateway
hironobuiga
2
290
Amazon Bedrock AgentCore 認証・認可入門
hironobuiga
3
640
AgentCoreで実現するマルチテナントAIエージェント
hironobuiga
2
140
FlutterでGraphQLを扱う
hironobuiga
0
25
FlutterでScrollViewとExpandedを併用し てSignIn / SignUp画面 など レイアウトを作成する
hironobuiga
0
22
Data Race and Actor
hironobuiga
0
84
20210625-meet-async-await@swift愛好会
hironobuiga
1
1.7k
Swift 5.1の変更点
hironobuiga
0
820
Other Decks in Technology
See All in Technology
電子辞書Brainをネットに繋げてみた(自力編)
raspython3
0
480
トークン数だけでは測れない — Claude Code 組織展開の効果検証から学んだこと
makikub
0
130
Agentic ERPをどう設計するか ー 受発注エージェントを動かす、現場の知見と設計思想ー
recerqainc
1
1.5k
AIガバナンス実践 - 生成AIコネクタのデータ漏洩リスクと実務対策
knishioka
0
190
10倍の生産性を実現するAI駆動並列エージェントのすべて
kumaiu
2
250
形式手法特論:公平性制約の位相的特徴づけ #kernelvm / Kernel VM Study Kansai 12th
ytaka23
1
750
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.8k
「速く作る」から「正しく作る」へ ─ 生成AI時代の開発フロー改革の ロードマップと実行 ─
starfish719
0
7.7k
正解のないAIプロダクトをどう導くか?dodaが挑む、ユーザーの『本音』を構造化する評価設計と検証のリアル
techtekt
PRO
0
180
「嘘をつくテスト」の失敗例から学ぶ 良いテストコード #frontend_phpcon_do
asumikam
0
460
イベントストーミングとKiroの仕様駆動開発で実現する要件の認識合わせプロセス
syobochim
7
1.2k
個人の発見を、組織の知恵に 〜生成AI活用を"探索"から"組織の仕組み"へ〜
kintotechdev
2
990
Featured
See All Featured
Building an army of robots
kneath
306
46k
How to Ace a Technical Interview
jacobian
281
24k
Become a Pro
speakerdeck
PRO
31
6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Utilizing Notion as your number one productivity tool
mfonobong
4
310
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
BBQ
matthewcrist
89
10k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Designing Experiences People Love
moore
143
24k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
A Tale of Four Properties
chriscoyier
163
24k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Transcript
FlutterͰGraphQL ͷuseQueryΛ͏ ҏլɹ༟ల 2024/11/14 Flutter Tokyo #5
React.jsͱGraphQL ͷΈ߹ΘͤͰΈ͔͚Δίʔυ
React.js GraphQL const GET_SAMPLE = gql` query GetSample($id: ID!) {
sample(id: $id) { id name } } `; function SampleView({ id }: { id: string }) { const { loading, error, data } = useQuery(GET_SAMPLE, { variables: { id }, }); if (loading) return <p>ಡΈࠐΈத...</p>; if (error) return <p>Τϥʔ͕ൃੜ͠·ͨ͠: {error.message}</p>; return <p>{data?.sample?.name}</p>; } export default SampleView;
React.js GraphQL const GET_SAMPLE = gql` query GetSample($id: ID!) {
sample(id: $id) { id name } } `; function SampleView({ id }: { id: string }) { const { loading, error, data } = useQuery(GET_SAMPLE, { variables: { id }, }); if (loading) return <p>ಡΈࠐΈத...</p>; if (error) return <p>Τϥʔ͕ൃੜ͠·ͨ͠: {error.message}</p>; return <p>{data?.sample?.name}</p>; } export default SampleView;
GraphQLͷuseQuery • GraphQL༻ͷReact Hook • ΫΤϦͷ࣮ߦͱঢ়ଶཧ͕؆୯ʹߦ͑Δ • σʔλऔಘதΤϥʔൃੜ࣌ͷॲཧΛ؆୯ʹཧͰ͖Δ • ΫΤϦͷมߋσʔλߋ৽͕ଈ࠲ʹө͞ΕɺϦΞΫςΟϒͳUI͕࣮
ݱͰ͖Δ
GraphQLͷuseQueryΛ FlutterͰ͍͍ͨ
Ͱ͖·͢ʂ
ࠓճͷલఏͳͲͳͲ
Flutter x GraphQL
Options • graphql_ fl utter • ferry • Artemis
Options • graphql_ fl utter • ferry • Artemis =>
Archived
Options • graphql_ fl utter • ferry • Artemis =>
Archived
ίʔυࣗಈੜ
graphql_ fl utterͷίʔυࣗಈੜ • graphql_codegen • graphql_ fl utterͷREADMEʹهࡌ͋Γ •
͜ͷϥΠϒϥϦ͕ے͕ྑͦ͞͏
graphql_ fl utter graphql_codegen fl utter_hooks
graphql_codegen x hooks • graphql_ fl utter READMEͷgraphql_codegenʹؔ͢Δهࡌ • This
package generate hooks and options which takes away the struggle of serialization and gives you con fi dence through type- safety. • graphql_codegen READMEͷهࡌ • fl utter_hooks (optional) to use generated operations hooks. Will be inside HookWidgets
garphql_codegen useQueryͷίʔυੜͯ͘͠ΕΔ
ྫ
Schema type Query { sample(id: ID!): Sample! } type Sample
{ id: ID! name: String! }
Query query Sample($id: ID!) { sample(id: $id) { __typename id
name } } sample.graphqlͷϑΝΠϧ໊Ͱ࡞
graphql_codegen ͷੜ sample.graphql.dart ͷ໋໊ͰϑΝΠϧ͕ੜ͞ΕΔ ίʔυ͕ͨ͘͞Μ͋Γ·͕͢ɺΑ͘ݟ͍ͯ͘ͱҎԼͷίʔυ͕ݟ͔ͭΓ·͢ graphql_flutter.QueryHookResult<Query$Sample> useQuery$Sample([Options$Query$Sample? options]) => graphql_flutter.useQuery(options
?? Options$Query$Sample()); class Options$Query$Sample extends graphql.QueryOptions<Query$Sample>
ੜ • useQuery${Query໊} ͰuseQueryͷϝιου͕ੜ͞Ε·͢ • ϝιουͷҾͷܕ Options$Query${Query໊}
ͬͯΈΔ class SamplePage extends HookWidget { const SamplePage({super.key}); @override Widget
build(BuildContext context) { final query = useQuery$Sample( Options$Query$Sample( fetchPolicy: FetchPolicy.cacheAndNetwork, variables: Variables$Query$Sample(id: '1'), ), ); if (query.result.isLoading) { return const Scaffold(body: CircularProgressIndicator()); } if (query.result.hasException) { return const Scaffold(body: Text('error')); } return Scaffold(body: Text(query.result.parsedData?.sample.name ?? 'Sample')); } }
ͬͯΈΔ class SamplePage extends HookWidget { … … @override Widget
build(BuildContext context) { final query = useQuery$Sample( Options$Query$Sample( fetchPolicy: FetchPolicy.cacheAndNetwork, variables: Variables$Query$Sample(id: '1'), ), ); … … } } HookWidgetͰ༻ buildϝιουͰ useQueryΛ༻͢Δ FetchPolicy͑Δ
ͬͯΈΔ class SamplePage extends HookWidget { … @override Widget build(BuildContext
context) { final query = useQuery$Sample( ……… ); if (query.result.isLoading) { return const Scaffold( body: CircularProgressIndicator()); } if (query.result.hasException) { return const Scaffold(body: Text('error')); } return Scaffold( body: Text(query.result.parsedData?.sample.name ?? 'Sample')); } } query͔Βloadingத Τϥʔ͔Ͳ͏͔ औಘ݁Ռ ͕औΕ·͢
ൺֱ
function SampleView() { const { loading, error, data } =
useQuery(GET_SAMPLE, { variables: { “1” }, }); if (loading) return <p>ಡΈࠐΈத...</p>; if (error) return <p>Τϥʔ</p>; return <p>{data?.sample?.name}</p>; } export default SampleView; class SamplePage extends HookWidget { const SamplePage({super.key}); @override Widget build(BuildContext context) { final query = useQuery$Sample( Options$Query$Sample( variables: Variables$Query$Sample(id: '1'), ), ); if (query.result.isLoading) { return const Text(‘ಡΈࠐΈத’); } if (query.result.hasException) { return const Text(‘Τϥʔ'); } return Text(query.result.parsedData?.sample.name ?? ''); } } React Flutter
͍͍ײ͡ʂ
Demo༻ΞϓϦ https://github.com/HironobuIga/ FlutterUseQuerySample
FlutterͰGraphQLͷ useQuery͕͑Δʂ
Thank you for listening!