项目需要所完成的,目前已用于生产环境~
微信小程序GraphQL客户端,点击图片观看演示demo
git clone https://github.com/Authing/wxapp-graphql
// 引入文件
var gql = require('path/to/graphql/wxgql.js');
var GraphQL = gql.GraphQL;
Page({
test: function() {
// 初始化对象
let gql = GraphQL({
url: 'https://users.authing.cn/graphql' // url必填
}, true); //第二个参数的true代表是否使用对象方法,如gql.query或gql.mutate,默认是函数方法,如gql({body: {query: '', variables: {}}}),建议写true,为true时可以使用promise
gql.query({
query: `query getAccessTokenByAppSecret($secret: String!, $clientId: String!){
getAccessTokenByAppSecret(secret: $secret, clientId: $clientId)
}`,
variables: {
secret: '427e24d3b7e289ae9469ab6724dc7ff0',
clientId: '5a9fa26cf8635a000185528c'
}
}).then(function(res) {
//成功
}).catch(function(error) {
//失败
});
}
});
var gql = require('path/to/graphql/wxgql.js');
var GraphQL = gql.GraphQL;
Page({
test: function() {
let gql = GraphQL({
url: 'https://users.authing.cn/graphql' // url必填
});
gql({
// 示例GraphQL查询, body必填
body: {
query: `query getAccessTokenByAppSecret($secret: String!, $clientId: String!){
getAccessTokenByAppSecret(secret: $secret, clientId: $clientId)
}`,
variables: {
secret: '427e24d3b7e289ae9469ab6724dc7ff0',
clientId: '5a9fa26cf8635a000185528c'
}
},
// 成功
success: function (res) {
console.log(res);
},
// 失败
fail: function (res) {
console.log(res);
},
// 执行完成
complete: function (res) {
console.log(res);
}
});
});