iT邦幫忙

2

Steps for Django GraphQL -- Front End

在前端想要 request graphql 的 api 很簡單
大致如下:

// data.query 是你的 query string(可直接貼上在 graphQI 測的字串)
// 若有需要輸入的條件變數,需在 query 後先宣告變數與型別 (mutation亦同),之後直接帶入變數
var data = {
    query: `query ( $name: String!){
        playData(name: $name) {
          LV
          SKILL
        }
    }`,
    // 前面若有宣告變數,在這邊給值
    variables: { 
        name: 'Charmander',
    }
}
// 這兩項 header 必帶
var headers = new Headers()
headers.append("Content-Type", "application/json")
headers.append("Accept", "application/json")

fetch("http://localhost:8010/graph/", {
// 必須用 POST 方法
    method: 'POST',
    headers: headers,
    body: JSON.stringify(data)
})

以上
終於結束囉 ^^


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
advancedor96
iT邦新手 5 級 ‧ 2018-01-04 17:34:45

thank you

我要留言

立即登入留言