<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohsen ZareZardeyni</title>
    <description>The latest articles on DEV Community by Mohsen ZareZardeyni (@mohsen89z).</description>
    <link>https://dev.to/mohsen89z</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F187625%2Ff119656c-23cd-4078-bac7-e24bb089d7b0.jpeg</url>
      <title>DEV Community: Mohsen ZareZardeyni</title>
      <link>https://dev.to/mohsen89z</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohsen89z"/>
    <language>en</language>
    <item>
      <title>How to resolve import for the .graphql file with typescript and webpack</title>
      <dc:creator>Mohsen ZareZardeyni</dc:creator>
      <pubDate>Wed, 10 Jul 2019 18:26:18 +0000</pubDate>
      <link>https://dev.to/open-graphql/how-to-resolve-import-for-the-graphql-file-with-typescript-and-webpack-35lf</link>
      <guid>https://dev.to/open-graphql/how-to-resolve-import-for-the-graphql-file-with-typescript-and-webpack-35lf</guid>
      <description>&lt;p&gt;Hi, I’m Mohsen ZareZardeyni, and I’m a software engineer at &lt;a href="https://sigmasoftwares.com/"&gt;Sigma Telecom LLC&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At Sigma, for developing our back office application, we decided to use GraphQL, Typescript and Apollo server. We choose Schema first approach and stored our schema in separate &lt;code&gt;.graphql&lt;/code&gt; files. In order to import our schema within our Typescript code, we ended up using Webpack as our transpiler.&lt;/p&gt;

&lt;p&gt;As I was looking for a way to do so, I didn’t find any good tutorial on this matter so I’m providing this tutorial for future researchers!🤠&lt;/p&gt;

&lt;p&gt;First, you need to add the following configuration to your &lt;code&gt;tsconfig.json&lt;/code&gt;. This will tell Typescript to use the &lt;code&gt;src/@types&lt;/code&gt; folder in addition to &lt;code&gt;node_modules/@types&lt;/code&gt; in order to identify your types.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then you need to introduce &lt;code&gt;.graphql&lt;/code&gt; files to Typescript. In order to do this, you need to create a &lt;code&gt;graphql.d.ts&lt;/code&gt; in your &lt;code&gt;src/@types&lt;/code&gt; folder. The following code will tell typescript every time it sees an imported file with the &lt;code&gt;.graphql&lt;/code&gt; extension, it will provide a &lt;code&gt;GraphQL DocumentNode&lt;/code&gt;, which is the type you need to provide for your GraphQL Schema.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In our case, we used apollo-server from &lt;a href="https://dev.to/t/apollo"&gt;Apollo Foundation&lt;/a&gt;, but any other GraphQL server library uses the same pattern. With previous steps, the following code will let you import your &lt;code&gt;.graphql&lt;/code&gt; files without any typing issue.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, the last step is to tell webpack how to treat &lt;code&gt;.graphql&lt;/code&gt; imports. The following code will tell &lt;code&gt;webpack&lt;/code&gt; every time it sees a &lt;code&gt;.graphql&lt;/code&gt; file, it should use &lt;code&gt;graphql-tag/loader&lt;/code&gt; in order to load the content.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Hope this helps you:)&lt;/p&gt;

&lt;p&gt;Also, you can find me on &lt;a href="https://www.linkedin.com/in/mohsen89z/"&gt;linkedin&lt;/a&gt; and &lt;a href="https://twitter.com/MohsenZZardeyni"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>typescript</category>
      <category>webpack</category>
      <category>node</category>
    </item>
  </channel>
</rss>
