使用Typescript +生成的内核作为包调用graphql-codegen查询时,无效的挂钩调用

时间:2020-04-04 17:44:29

标签: reactjs typescript graphql yarn-workspaces graphql-codegen

我正在使用带有npm软件包(具有生成的代码)和使用它的移动软件包的Yarn工作区。

当尝试从导入的查询进行调用时,我收到无效的挂接调用。在该组件中使用其他任何钩子(即useState)都可以正常工作。

我的移动软件包的package.json导入: Pybind11

我在core / src上有一个index.js文件,该文件具有:

"@workspace-library/core": "1.0.0",

我这样导入查询:

export * from "./generated/graphql";
export { apollo, useAuth, withAuth };

以防万一,我可以在我生成的/graphql.jsx中看到useArticlesQuery,

import { useArticlesQuery } from "@workspace-library/core"; const SidebarArticles: FunctionComponent<{ props: any }> = (props: any) => { const [test, setTest] = useState("false"); const data = useArticlesQuery({ fetchPolicy: "no-cache", notifyOnNetworkStatusChange: true, }); return ( <View> <Text>Heyhey</Text> </View> ); };

环境:

  • 操作系统:Ubuntu
  • “ @ graphql-codegen / cli”:“ ^ 1.13.1”,
  • “ @ graphql-codegen / typescript”:“ ^ 1.13.1”,
  • “ @ graphql-codegen / typescript-operations”:“ ^ 1.13.1”,
  • “ @ graphql-codegen / typescript-react-apollo”:“ ^ 1.13.1”,
  • 纱线工作区

其他上下文 有问题的错误:

export function useArticlesQuery(baseOptions) {
    return ApolloReactHooks.useQuery(ArticlesDocument, baseOptions);
}

1 个答案:

答案 0 :(得分:-2)

我遇到了同样的问题。不过使用 useQuery 是可行的。