Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Authing/wxapp-graphql
https://github.com/Authing/wxapp-graphql
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/Authing/wxapp-graphql
- Owner: Authing
- License: mit
- Created: 2022-07-27T07:14:45.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-07-27T07:15:09.000Z (over 2 years ago)
- Last Synced: 2024-09-18T09:13:22.640Z (about 2 months ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 5
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wechat-app - wxapp-graphql - 小程序 GraphQL 客户端 (工具)
- awesome-wechat-weapp - wxapp-graphql - 小程序 GraphQL 客户端 (工具)
- awesome-wechat-weapp - wxapp-graphql - 小程序GraphQL客户端 (工具)
README
# wxapp-graphql
一个适用于小程序的 GraphQL 客户端,由 Authing 开发维护。
## 使用 NPM 安装
``` shell
$ npm install wxapp-graphql --save
```如何在小程序里使用 NPM,请参考[这篇文章](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)。
## 使用
``` javascript
// 引入文件
var gql = require('wxapp-graphql');
var GraphQL = gql.GraphQL;Page({
test: function() {// 初始化对象
let gql = GraphQL({
url: 'https://users.authing.cn/graphql' // url 必填
}, true);
// query 查询,mutation 请使用 gql.mutate
gql.query({
query: `query getAccessTokenByAppSecret($secret: String!, $clientId: String!){
getAccessTokenByAppSecret(secret: $secret, clientId: $clientId)
}`,
variables: {
secret: '427e24d3b7e289ae9469ab6724dc7ff0',
clientId: '5a9fa26cf8635a000185528c'
}
}).then(function(res) {
//成功
console.log(res);
}).catch(function(error) {
//失败
console.log(error);
});
}
});```
## 发起 mutation 请求
``` javascript
gql.mutate({
mutation: 'YOUR_GQL',
variables: 'YOUR_variables'
})
```## 配置全局 header 和错误拦截
``` javascript
var gqlwx = require('../graphql/wxgql');
var GraphQL = gqlwx.GraphQL;var gql = GraphQL({
//设置全局 url
url: 'https://users.authing.cn/graphql', // url 必填//设置全居动态 header
header: function () {
return {
// something....
'X-Test-Header': 'test header content'
}
},//设置全居错误拦截
errorHandler: function (res) {
//do something
}
}, true
);module.exports = gql;
```全局详细配置请查看 [example](https://github.com/Authing/wxapp-graphql/blob/master/src/example/graphql.js).
## 参与贡献
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request## 获取帮助
Join us on forum: [#authing-chat](https://forum.authing.cn/)