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
32
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
290
FastMCP OAuth Proxy with Cognito
hironobuiga
3
360
Three-Legged OAuth in AgentCore Gateway
hironobuiga
2
310
Amazon Bedrock AgentCore 認証・認可入門
hironobuiga
3
670
AgentCoreで実現するマルチテナントAIエージェント
hironobuiga
2
180
FlutterでGraphQLを扱う
hironobuiga
0
27
FlutterでScrollViewとExpandedを併用し てSignIn / SignUp画面 など レイアウトを作成する
hironobuiga
0
28
Data Race and Actor
hironobuiga
0
88
20210625-meet-async-await@swift愛好会
hironobuiga
1
1.7k
Other Decks in Technology
See All in Technology
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
410
AI時代の開発生産性を捉え直す — 経営と現場をつなぐ「開発組織のオブザーバビリティ」— / AI Dev Ex Conference 2026
tkyowa
1
1.3k
AI工学特論: MLOps・継続的評価
asei
4
180
SREとQA 二人三脚で進めるSLO運用/sre-qa-slo
sugitak
0
1.2k
Amplify Gen2でbackend.tsにCDKを定義する/しない事によるCDKの挙動の違いとユースケース
smt7174
1
480
クラウドを使う側から、作る側へ / 大吉祥寺.pm 2026前夜祭
fujiwara3
3
970
全員がリーダーである世界へ キリマンジャロ登頂とシェアド・リーダー
jinwatanabe
0
120
生成AI×AWS CDK×AWS FISで"振り返れる"ミニGameDayをつくろう
yoshimi0227
2
520
AIコード生成×サプライチェーン攻撃 — PHPが直面する“二重の信頼問題
shinyasaita
0
450
事業成長とAI活用を止めないデータ基盤アーキテクチャの設計思想
hiracky16
0
360
OpenTelemetryにおけるGoのゼロコード・コンパイル時計装について #fukuokago
quiver
0
190
AI時代におけるテストの基礎の再定義 / Rethinking the Fundamentals of Testing in the AI Era
mineo_matsuya
11
3.2k
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.9k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
180
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
500
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
Are puppies a ranking factor?
jonoalderson
1
3.7k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
840
From π to Pie charts
rasagy
0
240
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
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!