weapp-graphql-request
v0.2.0
Published
This is a util fork form graphql-request and only worked in weapp environment
Downloads
6
Maintainers
Readme
weapp-graphql-request (WIP)
Forked from graphql-request
Minimal GraphQL client supporting weapp environment.
Install
npm i weapp-graphql-request weapp-fetch graphql
Quick Start
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.
Environment support
| weapp | alipay | swan | tt | qq | jd | quickapp | | ----- | ------ | ---- | --- | --- | --- | -------- | | √ | ? | ? | ? | ? | ? | ? |
Framework support
| uni-app | taro | others | | ------- | ---- | ------ | | √ | √ | ? |
Usages
Refers to graphql-request
You can read it's doc for usage, but there are some points not support.
File upload
, weapp has noBlob
/File
/FormData
class.
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 })