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
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
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
260
FastMCP OAuth Proxy with Cognito
hironobuiga
3
350
Three-Legged OAuth in AgentCore Gateway
hironobuiga
2
290
Amazon Bedrock AgentCore 認証・認可入門
hironobuiga
3
650
AgentCoreで実現するマルチテナントAIエージェント
hironobuiga
2
160
FlutterでGraphQLを扱う
hironobuiga
0
26
FlutterでScrollViewとExpandedを併用し てSignIn / SignUp画面 など レイアウトを作成する
hironobuiga
0
23
Data Race and Actor
hironobuiga
0
87
20210625-meet-async-await@swift愛好会
hironobuiga
1
1.7k
Other Decks in Technology
See All in Technology
フルAIで個人開発して学んだあれこれ / yuruai vol.1
isaoshimizu
0
150
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
120
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
1
440
“詰む”前に仕組みを作れ 〜技術の波に溺れないためのキャッチアップ術〜
takasyou
7
4.3k
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
190
PostgreSQL 19 新機能概要 OSC Hokkaido 2026
nori_shinoda
0
260
AI Agentをシステムに組み込む前にゆるく向き合ってみる
hayama17
0
170
OTel × Datadog で 「AI活用」を計測し、改善に繋げる
shihochan
2
1.1k
Amazon Redshift zero-ETL 統合を活用した軽量なマルチプロダクトデータ可視化基盤 / Lightweight Multi-Product Data Visualization with Amazon Redshift Zero-ETL
kaminashi
0
110
組織における AI-DLC 実践
askul
0
170
AWS Summit 2026で見えたSIerにとっての Amazon Quickの位置づけ
maf_0521
0
120
打造你的 AI 工作流:Agent Skill + MCP 實戰工作坊
appleboy
0
170
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
5.7k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
55k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Building Adaptive Systems
keathley
44
3.1k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
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!