{"id":13487231,"url":"https://github.com/Authing/wxapp-graphql","last_synced_at":"2025-03-27T21:32:10.395Z","repository":{"id":57400477,"uuid":"518349882","full_name":"Authing/wxapp-graphql","owner":"Authing","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-27T07:15:09.000Z","size":30,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-21T13:40:22.527Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Authing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-27T07:14:45.000Z","updated_at":"2024-11-05T02:48:29.000Z","dependencies_parsed_at":"2022-09-05T03:01:20.004Z","dependency_job_id":null,"html_url":"https://github.com/Authing/wxapp-graphql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authing%2Fwxapp-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authing%2Fwxapp-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authing%2Fwxapp-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authing%2Fwxapp-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Authing","download_url":"https://codeload.github.com/Authing/wxapp-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245927371,"owners_count":20695224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:00:56.890Z","updated_at":"2025-03-27T21:32:10.057Z","avatar_url":"https://github.com/Authing.png","language":"JavaScript","funding_links":[],"categories":["工具"],"sub_categories":[],"readme":"# wxapp-graphql\n\n\u003cdiv align=center\u003e\u003cimg width=\"300\" src=\"https://files.authing.co/authing-console/authing-logo-new-20210924.svg\"\u003e\u003c/div\u003e\n\u003cdiv align=center\u003e一个适用于小程序的 GraphQL 客户端，由 \u003ca href=\"https://authing.cn\" target=\"_blank\"\u003eAuthing\u003c/a\u003e 开发维护。\u003c/div\u003e\n\u003cbr/\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://badge.fury.io/js/wxapp-graphql\"\u003e\u003cimg src=\"https://badge.fury.io/js/wxapp-graphql.svg\" alt=\"npm version\" height=\"18\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/wxapp-graphql\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/wxapp-graphql\" alt=\"download\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://standardjs.com\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg\" alt=\"standardjs\"\u003e\u003c/a\u003e\n  \u003ca href=\"javascript:;\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/node-%3E=12-green.svg\" alt=\"Node\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr/\u003e\n\n## 使用 NPM 安装\n\n``` shell\n$ npm install wxapp-graphql --save\n```\n\n如何在小程序里使用 NPM，请参考[这篇文章](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)。\n\n## 使用\n\n``` javascript\n\n// 引入文件\nvar gql = require('wxapp-graphql');\nvar GraphQL = gql.GraphQL;\n\nPage({\n  test: function() {\n\n    // 初始化对象\n    let gql = GraphQL({\n      url: 'https://users.authing.cn/graphql' // url 必填 \n    }, true);\n    \n    // query 查询，mutation 请使用 gql.mutate\n    gql.query({\n        query: `query getAccessTokenByAppSecret($secret: String!, $clientId: String!){\n    getAccessTokenByAppSecret(secret: $secret, clientId: $clientId)\n}`,\n        variables: {\n          secret: '427e24d3b7e289ae9469ab6724dc7ff0',\n          clientId: '5a9fa26cf8635a000185528c'\n        }\n    }).then(function(res) {\n      //成功\n      console.log(res);\n    }).catch(function(error) {\n      //失败\n      console.log(error);\n    });\n    \n  }\n});\n\n```\n\n## 发起 mutation 请求\n\n``` javascript\ngql.mutate({\n  mutation: 'YOUR_GQL',\n  variables: 'YOUR_variables'\n})\n```\n\n## 配置全局 header 和错误拦截\n\n``` javascript\nvar gqlwx = require('../graphql/wxgql');\nvar GraphQL = gqlwx.GraphQL;\n\nvar gql = GraphQL({\n    //设置全局 url\n    url: 'https://users.authing.cn/graphql', // url 必填\n\n    //设置全居动态 header\n    header: function () {\n        return {\n            // something....\n            'X-Test-Header': 'test header content'\n        }\n    },\n\n    //设置全居错误拦截\n    errorHandler: function (res) {\n        //do something\n    }\n  }, true\n);\n\nmodule.exports = gql;\n```\n\n全局详细配置请查看 [example](https://github.com/Authing/wxapp-graphql/blob/master/src/example/graphql.js).\n\n## 参与贡献\n- Fork it\n- Create your feature branch (git checkout -b my-new-feature)\n- Commit your changes (git commit -am 'Add some feature')\n- Push to the branch (git push origin my-new-feature)\n- Create new Pull Request\n\n## 获取帮助\n\nJoin us on forum: [#authing-chat](https://forum.authing.cn/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAuthing%2Fwxapp-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAuthing%2Fwxapp-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAuthing%2Fwxapp-graphql/lists"}