babel-plugin-import-graphql
babel-plugin-import-graphql copied to clipboard
Import with TypeScript aliases gives error
Our project uses TS alias imports and we get the following error:
import Query from '@shared/file.graphql';
Error: Cannot find module '@shared/file.graphql'
Only relative imports work:
import Query from '../file.graphql';
Same here, but with using webpack aliases.
Yes:
No:
PS:
"gQLDir" is webpack aliases.
eError:
When using dynamic import, modifying ". Graphql" will trigger recompilation! But static import will not!
SO!!! Recommended: import('gQLDir/GraphQLDemo.graphql'); OR import('../../../graphQL/GraphQLDemo.graphql');
With the dynamic import I mentioned above, there is no need to use script commands to delete the cache.
Alias cannot be used with "babel-plugin-import-graphql". But!!! Only "graphql-tag/loader","babel-plugin-import-graphql" are not used, but aliases can be used. { test: /.(graphql|gql)$/i, use: [ { loader: 'graphql-tag/loader', }, ], },