This is a util fork form graphql-request and only worked in weapp environment
npm install weapp-graphql-request> Forked from graphql-request
Minimal GraphQL client supporting weapp environment.
``sh`
npm i weapp-graphql-request weapp-fetch graphql
`js
import { GraphQLClient } from 'weapp-graphql-request'
import { createFetch } from 'weapp-fetch'
// const weappFetch = createFetch(wx.request)
// const uniFetch = createFetch(uni.request)
// const taroFetch = createFetch(taro.request)
// etc..
const graphQLClient = new GraphQLClient('http://localhost:3000', {
fetch: weappFetch,
})
graphQLClient.request(query, variables).then((data) => console.log(data))
`
you should install weapp-fetch instead of other fetch implement because only this lib can run in weapp environment.
| weapp | alipay | swan | tt | qq | jd | quickapp |
| ----- | ------ | ---- | --- | --- | --- | -------- |
| √ | ? | ? | ? | ? | ? | ? |
| uni-app | taro | others |
| ------- | ---- | ------ |
| √ | √ | ? |
Refers to graphql-request
You can read it's doc for usage, but there are some points not support.
1. File upload, weapp has no Blob/File/FormData class.
`js
import { GraphQLWebSocketClient } from 'weapp-graphql-request'
const task = wx.connectSocket({
url: 'wss://example.qq.com',
header: {
'content-type': 'application/json',
},
protocols: ['protocol1'],
})
const wsClient = new GraphQLWebSocketClient(task, { onInit, onAcknowledged, onPing, onPong })
``