Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amplify API (GraphQL) が簡単すぎて泣けてくる #jawsug_asa #...

Amplify API (GraphQL) が簡単すぎて泣けてくる #jawsug_asa #jawsug

https://jawsug-asa.connpass.com/event/180589/
#jawsug_asa #jawsug

AWS Amplify の API (GraphQL) の話。

Kihara, Takuya

July 22, 2020
Tweet

More Decks by Kihara, Takuya

Other Decks in Technology

Transcript

  1. +"846(ேձKBXTVH@BTB ୭ 2 PHP Conference Hokkaido 2019 ໊લ ໦ݪ ୎໵

    / ɹɹ@tacck ॴଐ גࣜձࣾϊʔεσΟςʔϧ
 ։ൃDivision ٕज़ਪਐGroup / Leader ओ࠵ ΏΔWebษڧձ@ࡳຈ εϚʔτεϐʔΧʔͰ༡΅͏ձ@ࡳຈ ޷͖ͳ
 AWSαʔϏε Route 53 ޷͖ͳ
 ϑΟΪϡΞεέʔτͷٕ εϓϨουɾΠʔάϧ
  2. +"846(ேձKBXTVH@BTB • AWS AppSync ΛɺϑϩϯτΤϯυ͔Β؆୯ʹ࢖͑Δɻ
 (ඪ४ͩͱɺ DynamoDB ΛετϨʔδͱͯ͠࢖͏ɻ) • Amplify

    CLI Λ࢖͏ͱɺ͍ΘΏΔ CRUD ͷΫΤϦΛ
 ੜ੒ͯ͘͠ΕΔɻ • ݺͼग़͠ํ͕Θ͔Ε͹ɺ͙͢ʹ࢖͑Δɻ "1* (SBQI2- 11
  3. +"846(ேձKBXTVH@BTB 13 import { API, graphqlOperation } from 'aws-amplify' import

    { getTodo, listTodos } from ‘@/graphql/queries’ ~~~ // queries const todo = await API.graphql( graphqlOperation(getTodo, { id: this.todoId }), ).catch(err => console.error('getTodo', err)) const todos = await API.graphql( graphqlOperation(listTodos, {}), ).catch(err => console.error('listTodos', err))
  4. +"846(ேձKBXTVH@BTB 14 import { API, graphqlOperation } from 'aws-amplify' import

    { createTodo, updateTodo, deleteTodo } from '@/graphql/mutations' ~~~ // mutations const createdTodo = await API.graphql( graphqlOperation(createTodo, { input: { name: 'new todo', description: 'sample description' }, }), ).catch(err => console.error('createTodo', err)) const updatedTodo = await API.graphql( graphqlOperation(updateTodo, { input: { id: createdTodo.data.createTodo.id, name: 'update todo', description: 'update description', }}), ).catch(err => console.error('updateTodo', err)) const deletedTodo = await API.graphql( graphqlOperation(deleteTodo, { input: { id: createdTodo.data.createTodo.id }, }), ).catch(err => console.error('deleteTodo', err))
  5. +"846(ேձKBXTVH@BTB 15 import { API, graphqlOperation } from 'aws-amplify' import

    { onCreateTodo, onUpdateTodo, onDeleteTodo } from '@/graphql/subscriptions' ~~~ // subscriptions const subscriptionCreateTodo = API.graphql( graphqlOperation(onCreateTodo), ).subscribe({ next: data => console.log(data) }) const subscriptionUpdateTodo = API.graphql( graphqlOperation(onUpdateTodo), ).subscribe({ next: data => console.log(data) }) const subscriptionDeleteTodo = API.graphql( graphqlOperation(onDeleteTodo), ).subscribe({ next: data => console.log(data) })
  6. +"846(ேձKBXTVH@BTB 16 const todo = await API.graphql( graphqlOperation(getTodo, { id:

    this.todoId }), ).catch(err => console.error('getTodo', err)) const createdTodo = await API.graphql( graphqlOperation(createTodo, { input: { name: 'new todo', description: 'sample description' }, }), ).catch(err => console.error('createTodo', err)) const subscriptionCreateTodo = API.graphql( graphqlOperation(onCreateTodo), ).subscribe({ next: data => console.log(data) })
  7. +"846(ேձKBXTVH@BTB 17 const todo = await API.graphql( graphqlOperation(getTodo, { id:

    this.todoId }), ).catch(err => console.error('getTodo', err)) const createdTodo = await API.graphql( graphqlOperation(createTodo, { input: { name: 'new todo', description: 'sample description' }, }), ).catch(err => console.error('createTodo', err)) const subscriptionCreateTodo = API.graphql( graphqlOperation(onCreateTodo), ).subscribe({ next: data => console.log(data) })