本文介绍了如何在来自客户端的grapqhl查询中添加hmac?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在 React Native 项目中使用 apolloclient,谁能指导我们如何在使用它进行的查询中添加 hmac?
We are using apolloclient in our React Native project, can anyone guide us on how we can add hmac in queries made using it?
推荐答案
希望对您有所帮助
import ApolloClient, { gql } from 'apollo-boost';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { print } from 'graphql/language/printer';
const baseURL = 'http://localhost:3000/';
const cache = new InMemoryCache({
addTypename: false
});
const apolloClient = new ApolloClient({
uri: baseURL,
cache,
request: (operation) => {
const { query, variables, operationName } = operation;
const payload = {
variables,
operationName,
query: print(query)
}
console.log(payload)
// custom headers
const headers = {
'X-API-KEY': '332dace0-e629-48bf-b664-d550ebfc828c',
'X-APP-ID': '52557818-b027-43a8-bf45-fb87f98cd96e',
'content-type': 'application/xjson',
'Authorization': token ? `Bearer ${token}` : '',
}
console.log(headers)
const token = ''; // create HMAC here
operation.setContext({
headers: {
...headers,
}
})
}
});
这篇关于如何在来自客户端的grapqhl查询中添加hmac?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!