fariba.j
fariba.j

Reputation: 1865

how to import a default exported graphql query in angular 12?

I have an angular 12 project and i wanna use graphql with apollo-angular. i create a category.js file with the codes below:

import gql from 'graphql-tag';

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

export default CATEGORIES_QUERY;

and in my component.ts i wanna import this js file:

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

but i got the error below:

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.

can anyone help?

Upvotes: 1

Views: 675

Answers (1)

Mikefox2k
Mikefox2k

Reputation: 76

You might need to add the following to tsconfig.json

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

This prevents typescript from applying module types to imported javascript.

Upvotes: 1

Related Questions