reactjs - 在graphql-request中设置firebase令牌的正确方法是什么
问题描述
我正在使用此代码导出 GraphQL 客户端,但 vscode 说
“仅当 'module' 选项设置为 'esnext' 或 'system',并且 'target' 选项设置为 'es2017' 或更高版本时,才允许使用顶级 'await' 表达式。”
import { GraphQLClient } from "graphql-request";
import { auth } from "../../firebase";
const token = await auth.currentUser?.getIdToken();
const requestHeaders = {
authorization: `Bearer ${token}`,
};
const graphQLClient = new GraphQLClient("http://localhost:4000/graphql", {
headers: requestHeaders,
});
export default graphQLClient;
而且我不能将它包装在一个函数中,因为它变成了一个不能像这样传递的异步函数。
const { data, isLoading, error } = useGetFeedQuery<GetFeedQuery, Error>(
await graphqlRequestClient()
);
解决方案
推荐阅读
- database - 使用 PostgreSQL 进行数据库设计:实现外键和主键
- vue.js - 在类星体上导入蓝鸟
- google-sheets - 使用 Google QUERY 从其他列返回 MAX 值和相应值
- python - Python - 寻找最佳的单字符通配符组合
- reactjs - 如何在 React js 中使用 jquery ui 滑块
- google-bigquery - 加入条件下的 BigQuery 子查询
- reactjs - 如何在 react-native 中向此按钮添加导航
- python - 球的代码出现错误 - ball = Ball(canvas, paddle, 'red') TypeError: __init__() missing 1 required positional argument: 'color'
- javascript - 函数更新联系人未定义,虽然已定义
- haskell - LYAH - 在链接 Writer monad 时理解关于“tell”的评论