Created
May 9, 2019 09:23
-
-
Save mohsen89z/443ed23ed6713846aa0c0199c3d8bc29 to your computer and use it in GitHub Desktop.
Resolve .graphql import in webpack and typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module '*.graphql' { | |
import { DocumentNode } from 'graphql'; | |
const MyQuery: DocumentNode; | |
export { MyQuery }; | |
export default MyQuery; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
... | |
"typeRoots": ["node_modules/@types", "src/@types"], | |
}, | |
"files": ["src/@types/graphql.d.ts"], | |
"include": ["src/**/*"], | |
"exclude": ["node_modules", "**/*.spec.ts"] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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