Coder Social home page Coder Social logo

wxapp-graphql's Introduction

wxapp-graphql

一个适用于小程序的 GraphQL 客户端,由 Authing 开发维护。

使用 NPM 安装

$ npm install wxapp-graphql --save

如何在小程序里使用 NPM,请参考这篇文章

使用

// 引入文件
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 请求

gql.mutate({
  mutation: 'YOUR_GQL',
  variables: 'YOUR_variables'
})

配置全局 header 和错误拦截

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.

Get Help

  1. Join us on Gitter: #authing-chat

wxapp-graphql's People

Contributors

leinue avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.