GraphQL WX-Cloud-Server Middleware
Installation
npm install --save wx-server-graphql
Server Simple Example
Just mount wx-server-graphql
as the /graphql
handler:
graphql/index.js
// 云函数入口文件const cloud = const graphqlWXServer = var buildSchema = // 使用 GraphQL Schema Language 创建一个 schemavar schema = // root 提供所有 API 入口端点相应的解析器函数var root = { return 'Hello world!' } cloud // 云函数入口函数exportsmain = async await
Client Simple Example
apolloProvider.js
// 利用link重置apolloClient请求grapql的方式为wx.cloud.callFunction// 参考文档 https://www.apollographql.com/blog/apollo-link-creating-your-custom-graphql-client-c865be0ce059/ { super thisoptions = options } { return { wxcloud } } wxcloud const client = link: name: 'graphql' cache: const Provider = <ApolloProvider client=client>children</ApolloProvider>