使用方法
1.clone项目:git clone https://github.com/Authing/wxapp-graphql
2.直接下载:https://github.com/Authing/wxapp-graphql
将文件中的wxgql.js复制到你的项目中并开始使用
话不多说,直接上代码
// 引入文件
var gql = require('path/to/graphql/wxgql.js');
var GraphQL = gql.GraphQL;
Page({
//查询
test1: 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: 'gfsg4545',
clientId: '4353'
}
}).then(function(res) {
//成功
}).catch(function(error) {
//失败
});
}
//修改
test2: function() {
// 初始化对象
let gql = GraphQL({url: 'https://users.authing.cn/graphql' // url必填 }, true); //第二个参数的true代表是否使用对象方法,如gql.query或gql.mutate,默认是函数方法,如gql({body: {mutation: '', variables: {}}}),建议写true,为true时可以使用promise
gql.mutate({
mutation: `mutation getAccessTokenByAppSecret($secret: String, $clientId: String){ getAccessTokenByAppSecret(secret: $secret, clientId: $clientId)}`,
variables: {
secret: '543fd',
clientId: 435'
}
}).then(function(res) {
//成功
}).catch(function(error) {
//失败
});
}
});
这样就可以使用了,是不是很简单呢!