Skip to content

Instantly share code, notes, and snippets.

@mohsen89z
Created May 9, 2019 09:23
Show Gist options
  • Save mohsen89z/443ed23ed6713846aa0c0199c3d8bc29 to your computer and use it in GitHub Desktop.
Save mohsen89z/443ed23ed6713846aa0c0199c3d8bc29 to your computer and use it in GitHub Desktop.
Resolve .graphql import in webpack and typescript
declare module '*.graphql' {
import { DocumentNode } from 'graphql';
const MyQuery: DocumentNode;
export { MyQuery };
export default MyQuery;
}
import { ApolloServer } from 'apollo-server'
import { resolvers } from './graphql/resolvers'
import { MyQuery } from './graphql/Query.graphql'
const server = new ApolloServer({
typeDefs: MyQuery,
resolvers,
})
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
})
{
"compilerOptions": {
...
"typeRoots": ["node_modules/@types", "src/@types"],
},
"files": ["src/@types/graphql.d.ts"],
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
module.exports = {
...
module: {
...
rules: [
...
{
test: /\.graphql$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment