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
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
LLMを「主役」にしないための 3つの原則
techtekt
PRO
0
120
新規ゲーム開発におけるAI駆動開発のリアル
202409e2
0
2.5k
BigQuery の Cross-cloud Lakehouse への歩み
phaya72
2
550
個人最適 から 全体最適 へ AI情報共有会・AIギルド・AI-DLC で進める カンリーの組織展開
rfdnxbro
0
1.5k
探して_入れて_作って_使う_Agent_Skills___LT.pdf
peintangos
2
160
MIERUNE JCT 発表資料「宇宙から伊能忠敬ごっこ」
syuchimu
0
180
サプライチェーンセキュリティの空白地帯 - 信頼できる”依存性”の未来を考える
rung
PRO
2
700
Amazon Bedrock AgentCore ワークショップ JAWS UG TOHOKU / amazon-bedrock-agentcore-workshop-jawsug-tohoku-2026
gawa
8
270
「コーディング」しない人のための Claude Code 入門 ChatGPT の次の一歩 — 業務に組み込む 育成・共有・自動化
rfdnxbro
2
1.2k
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
Djangoユーザが知っ得なPostgreSQL機能 - 設計の選択肢を増やす / Djang-use-PostgreSQL
soudai
PRO
0
180
AIを「創る」と「使う」の循環 — HRテックが実践するリアルなAI組織実装
taketo957
0
1.5k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Evolving SEO for Evolving Search Engines
ryanjones
0
210
Making Projects Easy
brettharned
120
6.7k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
360
New Earth Scene 8
popppiees
3
2.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Embracing the Ebb and Flow
colly
88
5.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
130
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Documentation Writing (for coders)
carmenintech
77
5.4k
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!