【问题标题】:how to import a default exported graphql query in angular 12?如何在 Angular 12 中导入默认导出的 graphql 查询?
【发布时间】:2021-09-15 01:15:18
【问题描述】:

我有一个 angular 12 项目,我想将 graphql 与 apollo-angular 一起使用。我使用以下代码创建了一个 category.js 文件:

import gql from 'graphql-tag';

const CATEGORIES_QUERY = gql`
query Categories {
    categories {
        id
        name
    }
}
`;

export default CATEGORIES_QUERY;

在我的 component.ts 中我想导入这个 js 文件:

import CATEGORIES_QUERY from "../apollo/queries/category/categories";

但我收到以下错误:

Could not find a declaration file for module '../apollo/queries/category/categories'. 
'c:/Users/Diba Computer/vscode/blog- 
strapi/frontend/src/app/apollo/queries/category/categories.js' implicitly has an 'any' type.

谁能帮忙?

【问题讨论】:

    标签: angular graphql angular12 apollo-angular


    【解决方案1】:

    您可能需要将以下内容添加到tsconfig.json

    {
      "compilerOptions": {
        ...
      "allowJs": true,
      "checkJs": false,
        ...
      }
    }
    

    这会阻止 typescript 将模块类型应用于导入的 javascript。

    【讨论】:

      猜你喜欢
      • 2018-09-24
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 2022-12-07
      • 2020-05-25
      相关资源
      最近更新 更多