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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
40代で“やっとエンジニアになれた”――閉じた学びを開き、空の青さを知る / 20260628 Naoki Takahashi
shift_evolve
PRO
4
1.1k
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
190
AWS Summit 2026で見えたSIerにとっての Amazon Quickの位置づけ
maf_0521
0
120
自作お家AIエージェントスタックチャンFWで困っている所紹介
74th
0
150
テスト設計の本質を改めて考えてみる~生成AIを活用する時代だからこそ、作ったテストの説明性を高めよう~
yamasaki696
1
140
現場のトークンマネジメント
dak2
1
200
[チョークトーク資料]AWS DevOps Agent を使いこなす / AWS Dev Ops Agent Chalk Talk AWS Summit Japan 2026
kinunori
4
810
從開發到部署全都交給 AI:實作 AI 驅動的自動化流程
appleboy
0
180
Hatena Engineer Seminar 37 jj1uzh
jj1uzh
0
170
Microsoft のサポートとフィードバック総まとめ
murachiakira
PRO
0
120
「軸足」は 固定しなくていい - 熱量と強みで描く、しなやかなキャリアの形
kakehashi
PRO
1
280
水を運ぶ人としてのリーダーシップ
izumii19
4
1.1k
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
KATA
mclloyd
PRO
35
15k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
450
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
170
The SEO Collaboration Effect
kristinabergwall1
1
490
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Embracing the Ebb and Flow
colly
88
5.1k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
350
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!