在微信小程序里怎么搭配使用GraphiQL呢?

使用方法
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) {      
	 //失败    
	});   
} 

}); 

这样就可以使用了,是不是很简单呢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值