在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):nordsimon/graphql-client开源软件地址(OpenSource Url):https://github.com/nordsimon/graphql-client开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Simple GraphQL ClientSmall http client based on the fetch api. Uses isomorphic-fetch for wider support If query fails, errors are thrown with messages and query highlight for easy debug Installnpm install graphql-client -S How ToInitialize the client var client = require('graphql-client')({
url: 'http://your-host/graphql',
headers: {
Authorization: 'Bearer ' + token
}
}) Use the promise API WARNING: Make sure the Promise API is polyfilled for older browsers, you can use es6-promise var variables = {
query: "Search Query",
limit: 100,
from: 200
}
client.query(`
query search ($query: String, $from: Int, $limit: Int) {
search(query: $query, from: $from, limit: $limit) {
took,
totalHits,
hits {
name
}
}
}`, variables, function(req, res) {
if(res.status === 401) {
throw new Error('Not authorized')
}
})
.then(function(body) {
console.log(body)
})
.catch(function(err) {
console.log(err.message)
}) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论