Skip to content

Latest commit

 

History

History
164 lines (144 loc) · 4.19 KB

readme.md

File metadata and controls

164 lines (144 loc) · 4.19 KB

index


install

$ composer install
$ php artisan migrate --seed

Requirement

配合 https://github.com/pamcy/Rainy-To-Do-App 建立的 API

(API 介面使用 graphql - http://graphql.org/)

使用兩個不一樣的 Graphql 套件


graphql request example

  • fetch data

query {
  products(
    count: 2
    # page: 2
    orderBy: {
      field: "price"
      order: DESC
    }
  )
  {
    data {
      id
      title
      price
      source {
        name
      }
      category {
        name
      }
    }
    total
    per_page
    last_page
  }
}

or http get request

/graphql?query=query {products(count:2 orderBy:{field:"price" order:DESC}){data{id title price source{name} category{name}}total per_page last_page}}

response

{
  "data": {
    "products": {
      "data": [
        {
          "id": 2,
          "source_id": 1,
          "title": "親子生態觀察 - 基隆八斗子潮境公園",
          "description": "做為海島子民,我們應該從小多了解台灣美麗的海岸線地型,才會知道豐富生態有多麼的珍貴。趁著兒童連假,帶著孩子來到基隆八斗子潮境公園,探訪這裡都住了哪些可愛的居民?面臨艱困的生存環境,他們又有哪些厲害的本領呢?",
          "price": 600,
          "link": "/product/3196",
          "img": "//d1f5je0f1yvok5.cloudfront.net/photo/n/g/f/ngfJsvXYDNfBjmByMVLULQ_o.jpg",
          "created_at": "2019-04-30 03:14:15",
          "source": {
            "name": "niceday"
          },
          "category": {
            "name": "愛上戶外"
          }
        },
        {
          "id": 4,
          "source_id": 1,
          "title": ": 多肉木器小品 : 禪風與森林綠意的結合",
          "description": "與其他植物相較,厚實的多肉植物多了種樸拙穩重,透過溫潤的木器及生氣蓬勃的多肉植物,組合出溫暖人心的多肉小品。適合擺在窗邊,跟著多肉追逐陽光、感受微風,為生活點綴森林的氣息,送禮自用兩相宜!",
          "price": 500,
          "link": "/product/3729",
          "img": "//d1f5je0f1yvok5.cloudfront.net/photo/G/d/K/GdKxV_6,AERcQs1883_HTQ_o.jpg",
          "created_at": "2019-04-30 03:14:15",
          "source": {
            "name": "niceday"
          },
          "category": {
            "name": "藝文手作"
          }
        }
      ],
      "total": 5,
      "per_page": 3,
      "last_page": 2
    }
  }
}
  • batch insert

mutation {
  insertProducts(
    data: [
      {
      	source: "niceday"
        prefix_url: "//play.niceday.tw"
      	category: "愛上戶外"
      	title: "title 123"
      	description: "desc 123"
      	link: "cola.io/1234"
      	img: "//cola.io/abc.jpg"
      	price: "$ 1,234 起"
      }
    ]
  ) {
    affected_rows
  }
}

or http get request

/graphql?query=mutation{insertProducts(data:[{source:"niceday" prefix_url:"//play.niceday.tw" category:"愛上戶外" title:"title 123" description:"desc 123" link:"cola.io/1234" img: "//cola.io/abc.jpg" price:"$ 1,234 起"}]){affected_rows}}

response

{
  "data": {
    "insertProducts": {
      "affected_rows": 1
    }
  }
}