首页 > 解决方案 > 在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()
  );

标签: reactjsfirebasegraphql

解决方案


推荐阅读