<?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: Jace Warren</title>
    <description>The latest articles on DEV Community by Jace Warren (@keatz55).</description>
    <link>https://dev.to/keatz55</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%2F51469%2Fc9d7627b-8d58-4085-9900-142b04dc050b.jpeg</url>
      <title>DEV Community: Jace Warren</title>
      <link>https://dev.to/keatz55</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keatz55"/>
    <language>en</language>
    <item>
      <title>What are some file structure best practices for apollo server?</title>
      <dc:creator>Jace Warren</dc:creator>
      <pubDate>Sat, 28 Jul 2018 00:53:22 +0000</pubDate>
      <link>https://dev.to/keatz55/what-are-some-file-structure-best-practices-for-apollo-server-2ii5</link>
      <guid>https://dev.to/keatz55/what-are-some-file-structure-best-practices-for-apollo-server-2ii5</guid>
      <description>&lt;p&gt;What are people finding as a best practice for folder structure in your apollo server? &lt;/p&gt;

&lt;p&gt;E.g. I'm wondering if it would be a good idea to structure things like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
    enum/
    input/
    interface/
    mock/
    mutation/
    query/
    resolver/
    scalar/
    subscription/
    type/
    server.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I was thinking I could merge everything together like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import http from "http";
import express from "express";
import { ApolloServer } from "apollo-server-express";
import { makeExecutableSchema } from "graphql-tools";
import { mergeResolvers, mergeTypes } from "merge-graphql-schemas";
import path from "path";
import glob from "glob";
import fs from "fs";

(async () =&amp;gt; {
  //   TypeDefs
  const typeDefs = glob
    .sync(path.join(__dirname, "./**/*.graphql"))
    .map(f =&amp;gt; fs.readFileSync(f, { encoding: "utf8" }));

  // Resolvers
  const resolvers = await Promise.all(
    glob
      .sync(path.join(__dirname, "./**/*.resolver.ts"))
      .map(async f =&amp;gt; (await import(f)).resolver)
  );

  //   Mocks
  const mocks = await Promise.all(
    glob
      .sync(path.join(__dirname, "./**/*.mock.ts"))
      .map(async f =&amp;gt; (await import(f)).mock)
  );

  const schema = makeExecutableSchema({
    resolvers: mergeResolvers(resolvers),
    resolverValidationOptions: {
      requireResolversForResolveType: false
    },
    typeDefs: mergeTypes(typeDefs)
  });

  const PORT = 4000;
  const app = express();
  const server = new ApolloServer({
    mocks: Object.assign({}, ...mocks),
    schema
  });
  server.applyMiddleware({ app });

  const httpServer = http.createServer(app);
  server.installSubscriptionHandlers(httpServer);

  httpServer.listen(PORT, () =&amp;gt; {
    console.log(
      `🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`
    );
    console.log(
      `🚀 Subscriptions ready at ws://localhost:${PORT}${
        server.subscriptionsPath
      }`
    );
  });
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think?&lt;/p&gt;

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