<?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: Uri Goldshtein</title>
    <description>The latest articles on DEV Community by Uri Goldshtein (@urigo).</description>
    <link>https://dev.to/urigo</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%2F106718%2F1acaee8e-bd2c-4998-8331-33b7d892c553.png</url>
      <title>DEV Community: Uri Goldshtein</title>
      <link>https://dev.to/urigo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/urigo"/>
    <language>en</language>
    <item>
      <title>GraphQL Modules — Feature based GraphQL Modules at scale</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:18 +0000</pubDate>
      <link>https://dev.to/urigo/graphql-modules-feature-based-graphql-modules-at-scale-1bpa</link>
      <guid>https://dev.to/urigo/graphql-modules-feature-based-graphql-modules-at-scale-1bpa</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OG8_Hcj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A44e5SD72vLOc9h_Nz_Aqhg.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OG8_Hcj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A44e5SD72vLOc9h_Nz_Aqhg.png%3Fraw%3Dtrue" alt="" title="https://graphql-modules.com/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  GraphQL Modules — Feature based GraphQL Modules at scale
&lt;/h1&gt;

&lt;p&gt;Today we are happy to announce that we are open sourcing a framework we’ve been using for the past couple of months in production — &lt;a href="https://graphql-modules.com/"&gt;GraphQL Modules&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Yet another framework? well, kind of.. GraphQL Modules is a set of extra libraries, structures and guidelines around the amazing &lt;a href="https://www.apollographql.com/docs/apollo-server/"&gt;Apollo Server 2.0&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can and should use them as completely separate packages, each one is good for different use cases, but all together they represent our current philosophy of building large scale GraphQL servers.&lt;/p&gt;

&lt;p&gt;We would love to get feedback from the Apollo team and if they wish to use those ideas and integrate them into Apollo Server we would love to contribute. That’s why we’ve developed it as a set of independent tools under a single monorepo.&lt;/p&gt;

&lt;p&gt;The basic concept behind GraphQL Modules is to separate your GraphQL server into smaller, &lt;strong&gt;reusable,&lt;/strong&gt; &lt;strong&gt;feature based&lt;/strong&gt; parts.&lt;/p&gt;

&lt;p&gt;A basic and initial implementation of a GraphQL server usually includes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m6znxpwj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ABZO6RkX1KUHyH04mnWDcng.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m6znxpwj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ABZO6RkX1KUHyH04mnWDcng.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A more advanced implementation will usually use a context to inject things like data models, data sources, fetchers, etc, like Apollo Server 2.0 provides us with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q_80qCBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AFzIxW6sm6SOHdi1DvDSMxg.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q_80qCBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AFzIxW6sm6SOHdi1DvDSMxg.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Usually, for simple use cases, the example above will do.&lt;/p&gt;

&lt;p&gt;But as applications grow, their code and schematic relationships becomes bigger and more complex, which can make schema maintenance a hard and agonizing thing to work with.&lt;/p&gt;

&lt;p&gt;Some of the more old school, MVC frameworks adds few more layers after the resolvers layer, but most of them just implement separation based technical layers: controllers, models, etc.&lt;/p&gt;

&lt;p&gt;We argue that there is a better approach of writing your GraphQL Schema and implementation.&lt;/p&gt;

&lt;p&gt;We believe you should &lt;strong&gt;separates your GraphQL schema by modules&lt;/strong&gt;, or &lt;strong&gt;features&lt;/strong&gt;, and includes anything related to a specific part of the app under a “module” — which is just a simple directory. Each one of the GraphQL Modules libraries would help you in the gradual process of doing that.&lt;/p&gt;

&lt;p&gt;The modules are being defined by their GraphQL schema — so we’ve taken the “GraphQL First” approach lead by Apollo and combined it together with classic modularization tooling to create new ways of writing GraphQL servers!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0hD4wx_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ASWNLOo8BKHbPP_evaq-GEw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0hD4wx_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ASWNLOo8BKHbPP_evaq-GEw.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The GraphQL Modules toolset has tools to help with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Schema Separation&lt;/strong&gt; — declare your GraphQL schema in smaller pieces, which you can later move and reuse.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tools designed to create independent modules&lt;/strong&gt; — each module is completely independent and testable, and can be shared with other applications or even open sourced if needed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resolvers Composition&lt;/strong&gt; — with GraphQL Modules you can write your resolver as you wish, and let the app that hosts the module to wrap the resolvers and extend them. It’s implemented with a basic middleware API, but with more flexibility. That means that you can, for example, implement your entire module without knowing about the app authentication process, and assume that &lt;code&gt;currentUser&lt;/code&gt; will be injected for you by the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A clear, gradual path&lt;/strong&gt; from a very simple and fast, single-file modules, to scalable multi-file, multi-teams, multi-repo, multi-server modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A scalable structure for your GraphQL servers&lt;/strong&gt; — managing multiple teams and features, multiple microservices and servers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and more advanced tools, which you can choose to include when your schema gets into massive scale:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Communication Bridge&lt;/strong&gt; — We also let you send custom messages with payload between modules — that means you can even run modules in different microservices and easily interact between them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency Injection&lt;/strong&gt; — Implement your resolvers, and later, only when you see fit, improve their implementation by gradually introducing dependency injection. It also includes richer toolset around testing and mocking.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  A Basic Example
&lt;/h1&gt;

&lt;p&gt;In the following example, you can see a basic implementation for GraphQL Modules server, with 2 modules: &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Chat&lt;/code&gt;. Each module declares only the part that is relevant to it, and extends previously declared GraphQL types.&lt;/p&gt;

&lt;p&gt;So when &lt;code&gt;User&lt;/code&gt; module is loaded, the &lt;code&gt;type User&lt;/code&gt; is created, and when &lt;code&gt;Chat&lt;/code&gt; module is loaded, the &lt;code&gt;type User&lt;/code&gt; being extended with more fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@graphql-modules/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;UserModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./user-module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ChatModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./chat-module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;UserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;ChatModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@graphql-modules/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ChatModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
    # Query declared again, adding only the part of the schema that relevant
    type Query {
      myChats: [Chat]
    }

    # User declared again- extends any other `&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="s2"&gt;` type that loaded into the appModule
    type User {
      chats: [Chat]
    }

    type Chat {
      id: ID!
      users: [User]
      messages: [ChatMessage]
    }

    type ChatMessage {
      id: ID!
      content: String!
      user: User!
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;myChats&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getChats&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentUser&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;getChats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentUser&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;  
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// This module implements only the part of `User` it adds&lt;/span&gt;
      &lt;span class="na"&gt;chats&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getChats&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;getChats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;appModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./modules/app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appModule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ApolloServer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; 
  &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;introspection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@graphql-modules/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
    type Query {
      me: User
    }

    # This is a basic User, with just the basics of a user object
    type User {
      id: ID!
      username: String!
      email: String!
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;me&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;currentUser&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;currentUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="p"&gt;},&lt;/span&gt; 
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can and should adopt GraphQL Modules part by part, and you can try it now with your existing GraphQL server.&lt;/p&gt;

&lt;p&gt;What does a “&lt;em&gt;module&lt;/em&gt;” contain?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Schema (types declaration)&lt;/strong&gt; — each module can define its own Schema, and can extend other schema types (without explicitly providing them).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Thin resolvers implementation&lt;/strong&gt; — each module can implement its own resolvers, resulting in thin resolvers instead of giant files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Providers&lt;/strong&gt; — each module can have its own Providers, which are just classes/values/functions that you can use from your resolvers. Modules can load and use providers from other modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration&lt;/strong&gt; — each module can declare a strongly-typed config object, which the consuming app can provide it with.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependencies&lt;/strong&gt; — modules can be dependent on other modules (by its name or its &lt;code&gt;GraphQLModule&lt;/code&gt; instance, so you can easily create an ambiguous dependency that later could be changed).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  GraphQL Modules libraries
&lt;/h1&gt;

&lt;p&gt;GraphQL Modules is built as a toolkit, with the following tools, which you should individually and gradually adopt:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@​graphql-modules/epoxy&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  That will probably be the first tool you want to introduce into your server. The first step into organizing your server in a feature based structure&lt;/li&gt;
&lt;li&gt;  Epoxy is a small util that manages the schema merging. it allow you to merge everything in your schema, starting from types to enums, unions, directives and so on.&lt;/li&gt;
&lt;li&gt;  This is an important feature of GraphQL Modules — you can use it to separate your GraphQL types to smaller pieces and later on combine them into a single type.&lt;/li&gt;
&lt;li&gt;  We took the inspiration from &lt;a href="https://github.com/okgrow/merge-graphql-schemas"&gt;merge-graphql-schemas&lt;/a&gt;, and added some features on top of it to allow custom merging rules to make it easier to separate your schema.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;@​graphql-modules/core&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://graphql-modules.com/docs/introduction/resolvers-composition"&gt;Resolvers Composition&lt;/a&gt; — manages the app’s resolvers wrapping&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://graphql-modules.com/docs/introduction/context"&gt;Context building&lt;/a&gt; — each module can inject custom properties to the schema, and other modules can use it (for example, auth module can inject the current user, and other modules can use it)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://graphql-modules.com/docs/introduction/dependency-injection"&gt;Dependency injection and module dependencies management&lt;/a&gt; — when you start, there is no need of using DI is your server. but when your server gets big enough with a large number of modules which depends on each other, only then, DI becomes a very help thing that actually simplifies your code a lot. USE ONLY WHEN NECESSARY ;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find more tooling at your disposal like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@​graphql-modules/sonar —&lt;/strong&gt; a small util that helps you to find GraphQL schema and resolvers files, and include them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@​graphql-modules/logger —&lt;/strong&gt; a small logger, based on &lt;a href="https://github.com/winstonjs/winston"&gt;winston 3&lt;/a&gt;, which you can easily use in your app.&lt;/p&gt;

&lt;h1&gt;
  
  
  Get Started
&lt;/h1&gt;

&lt;p&gt;First thing, don’t go full in! Start by simply moving your code into feature based folders and structures with your existing tools.&lt;/p&gt;

&lt;p&gt;Then head over to &lt;a href="https://graphql-modules.com/"&gt;https://graphql-modules.com/&lt;/a&gt; and check out our tools and use them only when you see that they solve a real problem for you! (for us it has)&lt;/p&gt;

&lt;p&gt;Also check out &lt;a href="https://github.com/Urigo/graphql-modules"&gt;the repo&lt;/a&gt;’s README and &lt;a href="https://github.com/Urigo/graphql-modules#examples"&gt;a number of example apps&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You probably have many questions — How does this compare to other tools, how to use those libraries with X and so on.&lt;/p&gt;

&lt;p&gt;We will publish a series of blog posts in the coming weeks that will dive deep into each of the design decisions made here, so we want to hear your thoughts and questions, please comment here or on the &lt;a href="https://github.com/urigo/graphql-modules"&gt;Github repository&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Going to &lt;a href="https://summit.graphql.com/"&gt;GraphQL Summit&lt;/a&gt;? &lt;a href="https://github.com/urigo"&gt;I&lt;/a&gt; will be there and would love to get your questions and feedback on behalf of our team.&lt;/p&gt;

&lt;p&gt;All those tools were built by a passionate group of individual open source developers, otherwise known as &lt;a href="https://medium.com/the-guild"&gt;The Guild&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below there is a section of more deep dive thoughts that we will publish separate posts about in the coming weeks:&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Concepts and deep dive
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Modularizing a schema
&lt;/h2&gt;

&lt;p&gt;Everyone is talking about schema stitching and GraphQL Bindings. Where does that fit into the picture?&lt;/p&gt;

&lt;p&gt;Schema stitching is an amazing ability and concept, which helps you merge separated GraphQL servers into a single endpoint and opens up a lot of exciting use cases.&lt;/p&gt;

&lt;p&gt;But, with all the excitement, we’ve missed something much more basic than that — sometimes we still want to work on a single logical server, but we just want to separate the code according to features.&lt;/p&gt;

&lt;p&gt;We want to be able to do most of the merging work at build time, and only if really necessary, do the rest of the merging at runtime as a last resort.&lt;/p&gt;

&lt;p&gt;We want to split the code into separate teams and even create reusable modules which define their external APIs by a GraphQL Schema.&lt;/p&gt;

&lt;p&gt;Those modules can be npm modules, microservices or just separate folders inside a single server.&lt;/p&gt;

&lt;p&gt;Separating your schema to smaller parts is easier when you are dealing with &lt;code&gt;typeDefs&lt;/code&gt; and &lt;code&gt;resolvers&lt;/code&gt;— it’s more readable and easy to understand.&lt;/p&gt;

&lt;p&gt;We also wanted to allow developers to extend only specific types, without creating the entire schema. With GraphQL schema, you have to specify at least one field under &lt;code&gt;Query&lt;/code&gt; type, which is something that we did not want to enforce on our users.&lt;/p&gt;

&lt;p&gt;We see our approach as complementary to Schema Stitching and works together with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature-based implementation
&lt;/h2&gt;

&lt;p&gt;One of the most important things in GraphQL Module’s approach is the feature-based implementation.&lt;/p&gt;

&lt;p&gt;Nowadays, most frameworks are separating the layers based on the role of the layer — such as controllers, data-access and so on.&lt;/p&gt;

&lt;p&gt;GraphQL Modules has a different approach — separate to modules based on your server’s features, and allow it to manage its own layers within each module implementation.&lt;/p&gt;

&lt;p&gt;It’s easier to think about apps in a modular way, for example:&lt;/p&gt;

&lt;p&gt;Your awesome app needs a basic authentication, users management, user profiles, user galleries and a chat.&lt;/p&gt;

&lt;p&gt;Each one of these could be a module, and implement its own GraphQL schema and its own logic, and it could depend on other modules to provide some of the logic.&lt;/p&gt;

&lt;p&gt;Here’s a simple example for a GraphQL Schema as we described:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MMQCPaAv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AfnGup_baJ6OhKNzNmJ8Wrw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MMQCPaAv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AfnGup_baJ6OhKNzNmJ8Wrw.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if we think of apps in terms of features and then separate the schema by module, the modules separation will look like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XcQp4ULW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AZtOhO2PCRh6FDQanTk_yug.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XcQp4ULW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AZtOhO2PCRh6FDQanTk_yug.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, each module can declare only the part of the schema that it contributes, and the complete schema is a representation of all merged type definitions. Module can also depend, import and extend and customize the contents on other modules (for example, &lt;code&gt;User&lt;/code&gt; module, comes with &lt;code&gt;Auth&lt;/code&gt; inside it)&lt;/p&gt;

&lt;p&gt;The result of course, will be the same, because we are merging the schema into a single one, but the codebase will be much more organized and each module will have its own logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reusability of backend modules
&lt;/h2&gt;

&lt;p&gt;So now that we understood the power of feature-based implementation, it’s easier to grasp the idea behind code reusability.&lt;/p&gt;

&lt;p&gt;If we could implement the schema and the core of Auth and User module as “plug-and-play” — we will be able later to import it in other projects, with very minor changes (using configuration, dependency injection, or module composition).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How could we reuse complete modules that hold part of a schema?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, let’s take a &lt;code&gt;User&lt;/code&gt; type.&lt;/p&gt;

&lt;p&gt;Most of &lt;code&gt;User&lt;/code&gt; type schemas will contain &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt; and &lt;code&gt;username&lt;/code&gt; fields. The Mutation type will have &lt;code&gt;login&lt;/code&gt; and the &lt;code&gt;Query&lt;/code&gt; will have &lt;code&gt;user&lt;/code&gt; field to query for a specific user.&lt;/p&gt;

&lt;p&gt;We can re-use this type declaration.&lt;/p&gt;

&lt;p&gt;The actual implementation might differ between apps, according to the authentication provider, database and so on, but we can still implement the business logic in a simple resolver, and use dependency injector and ask the app that’s using the module to provide the actual authentication function (of course, with a complete TypeScript interface so we’ll know that we need to provide it ;) ).&lt;/p&gt;

&lt;p&gt;Let’s take it one step further. If we would like to add a profile picture to a user, we can add a new module named &lt;code&gt;UserProfile&lt;/code&gt; and re-declare the &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Mutation&lt;/code&gt; types again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;profilePicture&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Mutation&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;uploadProfilePicture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;!):&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This way, GraphQL Modules will merge the fields from this &lt;code&gt;User&lt;/code&gt; type into the complete &lt;code&gt;User&lt;/code&gt; type, and this module will only extend the &lt;code&gt;User&lt;/code&gt; type and &lt;code&gt;Mutation&lt;/code&gt; type with the required actions.&lt;/p&gt;

&lt;p&gt;So let’s say that we have the schema — how can we make this module generic and re-use it?&lt;/p&gt;

&lt;p&gt;This is how you declare this module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@graphql-modules/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;UserModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../user/users.provider&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IUserProfileModuleConfig&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;profilePictureFields&lt;/span&gt; &lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;uploadProfilePicture&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Readable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserProfileModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;IUserProfileModuleConfig&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;UserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
    type User {
      profilePicture: String
    }
    type Mutation {
      uploadProfilePicture(image: File!): User
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;profilePicture&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ModuleContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fieldName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profilePictureField&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;profilePic&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;Mutation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;uploadProfilePicture&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;injector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentUser&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;ModuleContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// using https://www.apollographql.com/docs/guides/file-uploads.html&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Get the external method for uploading files, this is provided by the app as config&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imageUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uploadProfilePicture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Get the field name&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fieldName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profilePictureField&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;profilePic&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Ask the injector for "Users" token, we are assuming that `user` module exposes it for us,&lt;/span&gt;
        &lt;span class="c1"&gt;// then, update the user with the uploaded url.&lt;/span&gt;
        &lt;span class="nx"&gt;injector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;imageUrl&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="c1"&gt;// Return the current user, we can assume that `currentUser` will be in the context because&lt;/span&gt;
        &lt;span class="c1"&gt;// of resolvers composition - we will explain it later.&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;currentUser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;We declare a config object, and the app will provide it for us, so we can later replace it with a different logic for uploading.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Scaling the codebase
&lt;/h2&gt;

&lt;p&gt;Now that we broke our app into individual modules, once our codebase grows, we can scale each module individually.&lt;/p&gt;

&lt;p&gt;What do I mean by scaling a codebase?&lt;/p&gt;

&lt;p&gt;Let’s say we start to have code parts we want to share between different modules.&lt;/p&gt;

&lt;p&gt;The current way of doing it in the existing GraphQL world is through a GraphQL context.&lt;/p&gt;

&lt;p&gt;This approach has proven itself to work, but at some point it becomes a big hassle to maintain, because GraphQL context is an object, which any part of the app can modify, edit and extend, and it can become really big pretty quickly.&lt;/p&gt;

&lt;p&gt;GraphQL modules let each module extend and inject fields to the &lt;code&gt;context\&lt;/code&gt; object, but this is something that you should use with caution, because I recommend the &lt;code&gt;context\&lt;/code&gt; to contain the actual &lt;code&gt;context\&lt;/code&gt; — which contains data such as global configuration, environment, the current user and so on.&lt;/p&gt;

&lt;p&gt;GraphQL modules only adds one field under the &lt;code&gt;context&lt;/code&gt;, called &lt;code&gt;injector&lt;/code&gt; which is the bridge that lets you access your GraphQLApp and the application Injector, and it lets you fetch your module’s config and providers.&lt;/p&gt;

&lt;p&gt;Modules can be a simple directory in a project or in a monorepo, or it could be a published NPM module — you have the power to choose how to manage your codebase according to your needs and preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependency Injection
&lt;/h2&gt;

&lt;p&gt;GraphQL Modules’ dependency injection is inspired by .NET and Java’s dependency injection which has proven itself to work pretty well over the years. With that being said, there were some issues with .NET and Java’s APIs, which we’ve tried to list and go through. We ran into some pretty interesting conclusions.&lt;/p&gt;

&lt;p&gt;We’ve learn that it’s not something that should be forced. Dependency injection makes sense in some specific use cases and you should need to use it only when it’s necessary and when it helps you move faster. So this concept should come more and more in handy as we scale up, we can simplify things, maintain our code with ease and manage our teams’ contributions!&lt;/p&gt;

&lt;p&gt;Having GraphQL Modules deployed across all of our Enterprise customers while also being used on our smaller applications, lead us to believe that we’ve found the optimal point of where you should use the concept of dependency injection, and when not.&lt;/p&gt;

&lt;p&gt;We’ve also came with the optimal API for dependency injection. It’s extremely easy to understand, and use.&lt;/p&gt;

&lt;p&gt;After a long research of the existing dependency injection solutions for JavaScript, we’ve decided to implement a simple Injector, that supports the needs of GraphQL-Modules ecosystem, and support circular dependencies and more.&lt;/p&gt;

&lt;p&gt;We’ve simplified the Dependency Injection API and exposed to you only the important parts, that we believe that are necessary for a GraphQL server development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication
&lt;/h2&gt;

&lt;p&gt;Check out the related blog post we wrote about it: &lt;a href="https://medium.com/the-guild/authentication-and-authorization-in-graphql-and-how-graphql-modules-can-help-fadc1ee5b0c2"&gt;https://medium.com/the-guild/authentication-and-authorization-in-graphql-and-how-graphql-modules-can-help-fadc1ee5b0c2&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing and mocking
&lt;/h2&gt;

&lt;p&gt;On our Enterprise applications, when we started using dependency injection, we no longer had to manage instances and bridge them together.&lt;/p&gt;

&lt;p&gt;We gained an abstraction that allowed us to test things easier and mock all http requests.&lt;/p&gt;

&lt;p&gt;Yes, mocking. DI really shines here.&lt;/p&gt;

&lt;p&gt;Thanks to mocking we can simulate many scenarios and check the backend against them.&lt;/p&gt;

&lt;p&gt;And when your codebase grows, you need to start thinking about managing dependencies between modules and how to avoid things like circular dependencies — unless you use DI which solves that problem for you.&lt;/p&gt;

&lt;p&gt;With the power of dependency injection, you can easily create a loose connection between modules, and base this connection on a token and on a TypeScript interface.&lt;/p&gt;

&lt;p&gt;It also means that testing is much easier — you can take your class/function and test it as an independent unit, and mock its dependencies easily.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;We see GraphQL Modules as the framework that finally being built from the ground up on the new and exciting capabilities of GraphQL and Apollo, while combining it in the right way with good old software best practices for scale like modularizations, strong typings and dependency injection.&lt;/p&gt;

&lt;p&gt;Now go and try it out — &lt;a href="https://graphql-modules.com/"&gt;https://graphql-modules.com/&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  All posts about GraphQL Modules
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/graphql-modules-feature-based-graphql-modules-at-scale-2d7b2b0da6da"&gt;GraphQL Modules — Feature based GraphQL Modules at scale&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/why-is-true-modular-encapsulation-so-important-in-large-scale-graphql-projects-ed1778b03600"&gt;Why is True Modular Encapsulation So Important in Large-Scale GraphQL Projects?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/p/f25a234a9762"&gt;Why did we implement our own Dependency Injection library for GraphQL-Modules?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/p/949cd2588e0"&gt;Scoped Providers in GraphQL-Modules Dependency Injection&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/writing-strict-typed-graphql-typescript-project-w-graphql-modules-and-graphql-code-generator-c22f6caa17b8"&gt;Writing a GraphQL TypeScript project w/ GraphQL-Modules and GraphQL-Code-Generator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/authentication-and-authorization-in-graphql-and-how-graphql-modules-can-help-fadc1ee5b0c2"&gt;Authentication and Authorization in GraphQL (and how GraphQL-Modules can help)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/authentication-with-accountsjs-graphql-modules-e0fb9799a9da"&gt;Authentication with AccountsJS &amp;amp; GraphQL Modules&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/the-guild/manage-circular-imports-hell-with-graphql-modules-4b1611dee781"&gt;Manage Circular Imports Hell with GraphQL-Modules&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Follow us on &lt;a href="https://github.com/Urigo/graphql-modules"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://medium.com/the-guild"&gt;&lt;strong&gt;Medium&lt;/strong&gt;&lt;/a&gt;, we are planning to release many more posts in the next couple of weeks about what we’ve learned using &lt;strong&gt;GraphQL&lt;/strong&gt; in recent years.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>New release of GraphQL Subscriptions for Javascript</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:16 +0000</pubDate>
      <link>https://dev.to/urigo/new-release-of-graphql-subscriptions-for-javascript-4522</link>
      <guid>https://dev.to/urigo/new-release-of-graphql-subscriptions-for-javascript-4522</guid>
      <description>&lt;h2&gt;
  
  
  Lifecycle events, async configuration, MQTT/Redis integrations and feedback from the community
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--49j8aMHj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AOI8unw4F2B2NF37jeRaypw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--49j8aMHj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AOI8unw4F2B2NF37jeRaypw.png%3Fraw%3Dtrue" alt="" title="Try it today from npm!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GraphQL subscriptions are a way to add realtime data streaming to your GraphQL API. Yesterday, we wrote about an exciting new development for the community: &lt;a href="https://dev-blog.apollodata.com/the-next-step-for-realtime-data-in-graphql-b564b72eb07b#.1dax8i99c"&gt;the new RFC to add GraphQL subscriptions to the spec&lt;/a&gt;. Today, we’ll talk about the new versions we recently released for our GraphQL subscriptions implementation, and the work we’ve done to get to this exciting place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where subscriptions started
&lt;/h2&gt;

&lt;p&gt;On the Apollo team, we’ve been passionate about realtime data in GraphQL, and subscriptions in particular, for a long time. We &lt;a href="https://dev-blog.apollodata.com/graphql-subscriptions-in-apollo-client-9a2457f015fb#.lg5kcvr7u"&gt;released the first version of our GraphQL subscriptions library&lt;/a&gt;, which was the start of our exploration, almost 6 months ago in September.&lt;/p&gt;

&lt;p&gt;While we initially launched this as a feature for Apollo Client, we quickly realized there was a lot of demand for this across the community, so we put together &lt;a href="https://dev-blog.apollodata.com/a-proposal-for-graphql-subscriptions-1d89b1934c18"&gt;a proposal for a subscriptions architecture&lt;/a&gt; that could work with any client or server.&lt;/p&gt;

&lt;p&gt;Since then, we’ve been hard at work improving the implementation libraries, using GraphQL subscriptions internally and getting feedback from the community.&lt;/p&gt;

&lt;h2&gt;
  
  
  The new releases
&lt;/h2&gt;

&lt;p&gt;In this post I want to talk about the latest releases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/apollographql/graphql-subscriptions"&gt;graphql-subscriptions&lt;/a&gt; 0.3.0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;subscriptions-transport-ws&lt;/a&gt; 0.5.0&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These releases included lots of merged PRs and issues fixed from community members who use GraphQL subscriptions in production. We put most of the effort into areas where we had received a lot of feedback from the community:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Improvements for authorization flows&lt;/li&gt;
&lt;li&gt;  More lifecycle hooks for the client, giving more control and expression with the connection&lt;/li&gt;
&lt;li&gt;  Improved websockets implementation&lt;/li&gt;
&lt;li&gt;  Integration with the MQTT protocol in addition to Redis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal was to make a flexible implementation while keeping the app-specific code easier. On top of that, we wanted to create smaller and more modular package by splitting the subscriptions client and subscriptions server into separate bundles.&lt;/p&gt;

&lt;h1&gt;
  
  
  Client and server lifecycle events
&lt;/h1&gt;

&lt;p&gt;One of the features most requested by the community was more lifecycle events to track both the state of a subscription and the state of the connection overall. Many of the issues we closed in the last few weeks were related to this missing feature — and now it’s finally here.&lt;/p&gt;

&lt;p&gt;With the new version of &lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;subscriptions-transport-ws&lt;/a&gt; you can subscribe for client lifecycle events: &lt;em&gt;connect&lt;/em&gt;, &lt;em&gt;disconnect&lt;/em&gt;, and &lt;em&gt;reconnect&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This gives client developers the ability to respond to those network changes. For example, you can let the user know the app is offline, clear state after logout, disconnect the websocket, or initiate a retry after the connection has reconnected.&lt;/p&gt;

&lt;p&gt;The new version also adds server lifecycle events: &lt;em&gt;connect&lt;/em&gt;, &lt;em&gt;disconnect&lt;/em&gt;, &lt;em&gt;subscribe&lt;/em&gt;, and &lt;em&gt;unsubscribe&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This gives the server developer easier control over authentication logic and the ability to clean up state on the client if the server decides to terminate the connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  New INIT transport message
&lt;/h2&gt;

&lt;p&gt;In addition to independent life cycle events, in the new version of &lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;subscriptions-transport-ws&lt;/a&gt;, we added a new type of WebSocket message, called &lt;code&gt;INIT&lt;/code&gt; , which gives developers the ability to pass custom arguments from the client to the server. You can think of this as a way to pass information would have been a header in HTTP.&lt;/p&gt;

&lt;p&gt;Using this new type of message, you can create an authorized WebSocket by passing your authorization data in the initial request and writing code that accepts or rejects the connection before accepting subscriptions from the client using the &lt;code&gt;onConnect&lt;/code&gt; callback.&lt;/p&gt;

&lt;p&gt;The following example creates a GraphQL subscriptions client and server, using the new initialization feature and lifecycle events:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;client.js&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SubscriptionClient } from ‘subscriptions-transport-ws’;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getAuthToken = () =&amp;gt; {
  // Implement your logic to get the client’s auth details
  return ‘DUMMY_TOKEN’;
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wsClient = new SubscriptionClient(`SERVER_URL_HERE`, {
  reconnect: true,
  connectionParams: {
    authToken: getAuthToken()
  }
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wsClient.subscribe({ query: `...` }, (errors, result) =&amp;gt; {
  console.log(errors, result);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// If you're using apollo, you can use `addGraphQLSubscriptions` to
// attach this client to your network interface
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;server.js&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SubscriptionManager, PubSub } from ‘graphql-subscriptions’;
import { SubscriptionServer } from ‘subscriptions-transport-ws’;
import schema from ‘./schema’;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pubsub = new PubSub();
const subscriptionManager = new SubscriptionManager({
  schema,
  pubsub
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = createServer(); // create new connect/express server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const subscriptionServer = new SubscriptionServer({
  subscriptionManager,
  onConnect: async ({ authToken }) =&amp;gt; {
    const user = await validateUser(authToken);
    if (!user) {
      throw new Error(‘Unauthorized!’);
    } else { 
      // The returned value will be part of the `context`
      // for the filter functions and resolvers
      return {
        user
      };
    }
  },
}, {
  server // or use existing server with different path
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Refactor and dependency improvements
&lt;/h1&gt;

&lt;p&gt;We also did some code refactor and made the API more flexible. For example, you can now use a Promise for lifecycle events, setupFunctions, setting up the pub/sub engine, and more.&lt;/p&gt;

&lt;p&gt;Also, there is now a &lt;code&gt;addGraphQLSubscriptions&lt;/code&gt; method in the client side bundle of &lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;subscriptions-transport-ws&lt;/a&gt; so that developers using Apollo Client no longer need to write this code every time. This method allows you to extend your Apollo network interface to execute GraphQL subscriptions over the WebSocket transport, while using the regular network interface for queries and mutations.&lt;/p&gt;

&lt;p&gt;We updated our implementation to use the &lt;a href="https://www.npmjs.com/package/ws"&gt;ws&lt;/a&gt; package for the server side websocket implementation. This means you can also use the client if your subscriptions client is in a server-side NodeJS environment (in browser environment, it’s better to use the native implementation of your browser).&lt;/p&gt;

&lt;p&gt;The new &lt;code&gt;ws&lt;/code&gt; dependency is much &lt;a href="http://websockets.github.io/ws/benchmarks.html"&gt;faster&lt;/a&gt; than our previous websocket library. It’s also smaller library and adds less overhead over the websocket standard, which means it’s easier to abstract out and change the implementation if you need to.&lt;/p&gt;

&lt;h1&gt;
  
  
  MQTT and Redis support
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/apollostack/graphql-subscriptions"&gt;graphql-subscriptions&lt;/a&gt; package exports a default in-process pub/sub implementation, but for the best result in production it’s better to use an external pub/sub product, such as Redis or an MQTT service.&lt;/p&gt;

&lt;p&gt;We worked with David Yahalomi to create the &lt;a href="https://github.com/davidyaha/graphql-redis-subscriptions"&gt;graphql-redis-subscriptions&lt;/a&gt; and &lt;a href="https://github.com/davidyaha/graphql-mqtt-subscriptions"&gt;graphql-mqtt-subscriptions&lt;/a&gt; packages, which can be easily dropped in as a replacement for the default PubSub object without making any changes to the rest of your code. Using an external pub/sub system gives you more publication features — such as persistence, caching, delivery guarantees and other optimizations.&lt;/p&gt;

&lt;h1&gt;
  
  
  What’s next
&lt;/h1&gt;

&lt;p&gt;Though we’ve been working on subscriptions for a while, there’s still a lot to be done. In the near future, we’re going to be making the experience of using GraphQL subscriptions a lot better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;GraphQL subscriptions specification.&lt;/strong&gt; Sashko Stubailo has been &lt;a href="https://dev-blog.apollodata.com/the-next-step-for-realtime-data-in-graphql-b564b72eb07b#.1dax8i99c"&gt;working closely&lt;/a&gt; with the GraphQL team from Facebook to add subscriptions to the official spec. We’re incorporating the lessons we learned from using subscriptions in production and the feedback we hear from the community.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation.&lt;/strong&gt; We are working on adding more documentation to our official docs site about how to add subscriptions to your app. In the meantime, the best place to read and learn about setting up GraphQL subscriptions are the &lt;a href="https://github.com/apollographql/graphql-subscriptions/blob/master/README.md"&gt;readme&lt;/a&gt; &lt;a href="https://github.com/apollographql/subscriptions-transport-ws/blob/master/README.md"&gt;files&lt;/a&gt; of the libraries and the &lt;a href="https://github.com/apollographql/?utf8=%E2%9C%93&amp;amp;q=githunt&amp;amp;type=&amp;amp;language="&gt;GitHunt example&lt;/a&gt; apps. &lt;strong&gt;Update&lt;/strong&gt;: check out our new docs for &lt;a href="http://dev.apollodata.com/react/subscriptions.html"&gt;Subscriptions with React&lt;/a&gt; and &lt;a href="http://dev.apollodata.com/tools/graphql-subscriptions/index.html"&gt;Subscriptions with GraphQL Server&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Making it easier to use subscriptions with Apollo Client.&lt;/strong&gt; We &lt;a href="https://github.com/apollographql/apollo-client/issues/1224"&gt;plan to improve&lt;/a&gt; &lt;code&gt;updateQuery\&lt;/code&gt; and &lt;code&gt;updateQueries\&lt;/code&gt; and expose a simpler, yet flexible, API for updating the store when data arrives from subscriptions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-life case studies.&lt;/strong&gt; Many of the improvements described in this post came from working on our internal apps that use these libraries, while also getting feedback from developers in the community who are using subscriptions in production. We’re going to tell that story in more detail soon.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’re going to write many more blog posts about those experiences and lessons we learned from using GraphQL subscriptions in production. Make sure to follow our publication so you won’t miss it!&lt;/p&gt;




&lt;p&gt;We also want to hear more from you! Try out GraphQL subscriptions with our libraries and tell us what we should do next, and where we can best improve! And if you are &lt;em&gt;really&lt;/em&gt; interested in GraphQL subscriptions and real-time features, did you know &lt;a href="https://www.meteor.com/careers#open-source-engineer"&gt;we’re hiring&lt;/a&gt;?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>GraphQL CLI is back! Your Swiss Army Knife for the GraphQL ecosystem</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:15 +0000</pubDate>
      <link>https://dev.to/urigo/graphql-cli-is-back-your-swiss-army-knife-for-the-graphql-ecosystem-24j7</link>
      <guid>https://dev.to/urigo/graphql-cli-is-back-your-swiss-army-knife-for-the-graphql-ecosystem-24j7</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W0MOo6H---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A_7z5TiN1g22xJpdOQbfZ1Q.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W0MOo6H---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A_7z5TiN1g22xJpdOQbfZ1Q.gif%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  GraphQL CLI is back! Your Swiss Army Knife for the GraphQL ecosystem
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Production-ready GraphQL app in seconds
&lt;/h2&gt;

&lt;h1&gt;
  
  
  TL;DR;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/urigo/graphql-cli"&gt;GraphQL CLI&lt;/a&gt; is a &lt;strong&gt;popular command-line tool&lt;/strong&gt; providing various tools for creating and maintaining GraphQL based applications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.prisma.io/blog/the-guild-takes-over-oss-libraries-vvluy2i4uevs"&gt;Prisma recently transferred the project to The Guild&lt;/a&gt; — and we &lt;strong&gt;completely rewrote&lt;/strong&gt; it and closed over 100 issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We’ve already fixed and added many commands but we are looking to &lt;strong&gt;learn and integrate&lt;/strong&gt; with tools and companies &lt;strong&gt;across the ecosystem!&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can now generate a &lt;strong&gt;full stack working app&lt;/strong&gt;, from a GraphQL schema &lt;strong&gt;model&lt;/strong&gt;, in &lt;strong&gt;2 minutes&lt;/strong&gt; using the init+generate commands!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is an alpha phase — &lt;strong&gt;we want your feedback&lt;/strong&gt;, as a user and as a tool creator — Please &lt;a href="https://github.com/Urigo/graphql-cli/issues/new/choose"&gt;create an issue&lt;/a&gt; and &lt;a href="https://discord.gg/xud7bH9"&gt;join our Discord channel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://youtu.be/NDrPeQB1v5w"&gt;https://youtu.be/NDrPeQB1v5w&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;The GraphQL CLI provides:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Helpful commands to improve your daily workflows, from starting a project to maintaining it for the long run&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rich ecosystem and compatibility with libraries, editors and IDEs based on a unified &lt;a href="https://medium.com/the-guild/graphql-config-708dd0e5d15f"&gt;graphql-config&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A powerful plugin system to extend GraphQL CLI with custom commands — supported by the community and The Guild&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  The main target of the GraphQL CLI is to provide a default entry point for the community to use proven techniques for building and deploying GraphQL enabled applications while being vendor agnostic.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Advanced developers and tool creators can &lt;strong&gt;extend&lt;/strong&gt; &lt;a href="https://github.com/urigo/graphql-cli"&gt;graphql-cli&lt;/a&gt; to provide additional capabilities while still benefiting from a robust set of default commands for daily use — We want to use the CLI to encourage open collaborations between different tool creators.&lt;/p&gt;




&lt;h1&gt;
  
  
  History
&lt;/h1&gt;

&lt;p&gt;Over the years the GraphQL ecosystem flourished and evolved towards more production-ready use cases with a large number of active community packages available.&lt;/p&gt;

&lt;p&gt;GraphQL evolved thanks to the large community and the many supporting libraries it has created.&lt;/p&gt;

&lt;p&gt;The GraphQL CLI has become a place for the community to share ideas and best practices across different solutions and libraries thanks &lt;a href="https://www.prisma.io/blog/new-tooling-to-improve-your-graphql-workflows-7240c81e1ba3"&gt;to the push from Prisma&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.prisma.io/blog/the-guild-takes-over-oss-libraries-vvluy2i4uevs"&gt;The Guild took over GraphQL CLI&lt;/a&gt; to continue on that promise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Making it as easy as possible create and deploy GraphQL based applications&lt;/li&gt;
&lt;li&gt;  Making it easier to maintain production-grade, scalable GraphQL applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of that while:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Keeping the CLI updated with the latest solutions and practices&lt;/li&gt;
&lt;li&gt;  Making it extensible and configurable without any solution bias — any approach and architecture could easily integrate and benefit from the CLI&lt;/li&gt;
&lt;li&gt;  Keeping the industry leading, long term open source library maintenance standard that The Guild is known for&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Try it out today
&lt;/h1&gt;

&lt;p&gt;We’ve already refactored most of the code, created a new structure, closed and fixed all the known issues and released a new alpha version.&lt;/p&gt;

&lt;p&gt;Install new version (follow the latest alpha in the &lt;a href="https://github.com/Urigo/graphql-cli/releases"&gt;releases page&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install graphql-cli@canary
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a new project with GraphQL CLI by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ graphql init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;GraphQL CLI will guide you and after only few seconds, your project will be ready to use!&lt;/p&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;End-to-end type safety&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Code generation + end-to-end type safety is a hot topic nowadays. Thanks to tools like &lt;a href="https://graphql-code-generator.com"&gt;&lt;strong&gt;GraphQL Code Generator&lt;/strong&gt;&lt;/a&gt; we’re able to produce flexible code for both backend and frontend, just from GraphQL Schema and Operations with Fragments.&lt;/p&gt;

&lt;p&gt;In GraphQL CLI, you get it out of the box by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ graphql codegen
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Discover what can be generator on &lt;a href="https://graphql-code-generator.com"&gt;GraphQL Codegen website&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Production ready GraphQL Backend
&lt;/h1&gt;

&lt;p&gt;Thanks to integration with &lt;a href="https://graphback.dev/"&gt;&lt;strong&gt;GraphBack&lt;/strong&gt;&lt;/a&gt;, you’re able to produce an entire Data Base, GraphQL schema with operations and strongly typed resolvers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ graphql generate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Take a look at &lt;a href="https://graphback.dev/"&gt;GraphBack website&lt;/a&gt; to learn more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Bulletproof your GraphQL API
&lt;/h1&gt;

&lt;p&gt;GraphQL CLI comes with most of the features of &lt;a href="https://graphql-inspector.com"&gt;&lt;strong&gt;GraphQL Inspector&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With just few simple commands you’re able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  detect breaking or dangerous changes&lt;/li&gt;
&lt;li&gt;  validate Operations and Fragments at build time&lt;/li&gt;
&lt;li&gt;  analyze the usage of GraphQL Schema (unused types and fields)&lt;/li&gt;
&lt;li&gt;  find duplicates and similar GraphQL Types&lt;/li&gt;
&lt;li&gt;  serve faked GraphQL schema
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ graphql diff
$ graphql similar
$ graphql validate
$ graphql coverage
$ graphql serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://graphql-inspector.com"&gt;GraphQL Inspector docs&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  This is just the start!
&lt;/h1&gt;

&lt;p&gt;The GraphQL CLI has been rewritten in order to make it extremely customizable and extensible.&lt;/p&gt;

&lt;p&gt;Our goal is to make sure that any tool can work and benefit from this setup.&lt;/p&gt;

&lt;p&gt;The CLI offers freedom for anyone to create any command that will extend their workflows by creating separate library. Alternatively you can open a conversation about new command that can be included into our supported set of commands.&lt;/p&gt;

&lt;p&gt;If you prefer to use all of the Apollo toolings and products, AppSync’s solutions, Prisma, OneGraph, Hasura, Postgraphile or any other tool — we want to make the GraphQL CLI the best supporting tool for your stack.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  We won’t impose any choices on the users. We want the community to lead and have template generators for any technology.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;This project is completely open and free from any bias and we are open to any feedback and collaboration with anyone from the community. Please reach out!&lt;/p&gt;

&lt;h1&gt;
  
  
  Example use cases of GraphQL CLI
&lt;/h1&gt;

&lt;p&gt;The CLI gives you the ability to build a base template with your favorite stack and tools.&lt;/p&gt;

&lt;p&gt;Templates can be based on graphql.js, Apollo, Nexus, TypeGraphQL or anything other framework. Creating a custom template may help to enforce a specific structure that fits your product and company.&lt;/p&gt;

&lt;p&gt;The CLI comes with two default templates that provide a seamless starting point for both backend and frontend, both could be pushed to production in a short time period.&lt;/p&gt;

&lt;p&gt;Additionally, for existing applications, the CLI will support migrating existing databases or REST API to GraphQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production-ready GraphQL app in seconds
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Or “Making GraphQL easy — From nothing to a full production-ready app in 2 minutes — with any stack!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are many great GraphQL boilerplate repositories on available Github.&lt;/p&gt;

&lt;p&gt;But when using those, it is often hard to adjust those to real business cases.&lt;/p&gt;

&lt;p&gt;As an alternative to sample apps, developers can rely on frameworks that provide a high level of abstraction.&lt;/p&gt;

&lt;p&gt;But technologies that offer rapid application development might often come at the cost of the maintenance and flexibility that can seriously limit the extensibility of your application server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ graphql init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We believe that making it easy to start with GraphQL is extremely important, but without sacrificing other factors like extensibility, scalability and wider control.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Simple shouldn’t equal bad architecture.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;GraphQL CLI addresses this very important problem in the core by utilizing two main concepts: code generation and rich ecosystem of base templates.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;graphql init&lt;/code&gt; command is trying to address three simple questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Can we build an application template that can offer production-ready capabilities and yet is simple enough to work without extensive learning?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Can we provide our data model as input to the GraphQL engine and benefit from autogenerated data access methods?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Can we use the same techniques for an existing application and generate partial models?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  You can think of it as a smarter &lt;code&gt;create-react-app&lt;/code&gt;, that works on a full-stack and understands your data model.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are calling leading boilerplate creators and frameworks to collaborate with us. We can help you expose your boilerplates also as templates for the init command.&lt;/p&gt;

&lt;p&gt;We would also love feedback from internal infrastructure teams from companies who wish to create their own best practices and guidelines.&lt;/p&gt;

&lt;p&gt;For more information please refer to &lt;a href="https://github.com/aerogear/graphback/"&gt;https://github.com/aerogear/graphback&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One config to rule them all — GraphQL Config
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;At the heart of a project created using GraphQL CLI is the GraphQL Config file. It lets the CLI know where all of the GraphQL parts are.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Config is essential for CLI templates and for the command creators that can utilize its extensibility to save additional metadata. Thanks to &lt;a href="https://graphql-config.com"&gt;&lt;code&gt;graphql-config&lt;/code&gt;&lt;/a&gt;, the CLI can provide seamless support for every extension and streamline development experience on top of the GraphQL CLI generated projects and corresponding templates.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more information about GraphQL Config, you can &lt;a href="https://graphql-config.com"&gt;click here to learn more.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration from 3.x.x to 4.x.x
&lt;/h2&gt;

&lt;p&gt;We have provided a complete migration document for existing users who wish to update to the latest version of the CLI. Please keep in mind that CLI is still in the alpha phase and we are looking for the feedback before officially releasing a final version of the CLI.&lt;/p&gt;

&lt;p&gt;Please follow &lt;a href="https://github.com/Urigo/graphql-cli/blob/master/MIGRATION.md"&gt;https://github.com/Urigo/graphql-cli/blob/master/MIGRATION.md&lt;/a&gt; migration guide.&lt;/p&gt;




&lt;h1&gt;
  
  
  Help us to shape the GraphQL ecosystem
&lt;/h1&gt;

&lt;p&gt;Start using the GraphQL CLI today!&lt;/p&gt;

&lt;p&gt;Even though we are in an alpha phase, the CLI is fully usable and ready for the community to adopt it.&lt;/p&gt;

&lt;p&gt;Our team is open to any suggestions and ideas for new commands.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We will support and answer all your questions on &lt;a href="https://github.com/urigo/graphql-cli"&gt;Github&lt;/a&gt; and on our &lt;a href="https://discord.gg/xud7bH9"&gt;Discord channel&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>The Guild is taking over maintenance of merge-graphql-schemas, so let’s talk about GraphQL Schema management</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:14 +0000</pubDate>
      <link>https://dev.to/urigo/the-guild-is-taking-over-maintenance-of-merge-graphql-schemas-so-let-s-talk-about-graphql-schema-management-5a9c</link>
      <guid>https://dev.to/urigo/the-guild-is-taking-over-maintenance-of-merge-graphql-schemas-so-let-s-talk-about-graphql-schema-management-5a9c</guid>
      <description>&lt;p&gt;How stitching, federation and modules all fit together?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CopLzHxQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A_wzuTgyI7I6asXpj-BhQfQ.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CopLzHxQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A_wzuTgyI7I6asXpj-BhQfQ.png%3Fraw%3Dtrue" alt="" title="merge-graphql-schemas as a new home"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;After many years of supporting the community, the OK-Grow! Team is transferring ownership and maintenance of &lt;a href="https://github.com/urigo/merge-graphql-schemas"&gt;&lt;strong&gt;merge-graphql-schemas&lt;/strong&gt;&lt;/a&gt; to The Guild&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/urigo/merge-graphql-schemas"&gt;merge-graphql-schemas&lt;/a&gt; will be added to the existing Schema management tools already created by &lt;a href="https://github.com/the-guild-org"&gt;&lt;strong&gt;The Guild&lt;/strong&gt;&lt;/a&gt; (&lt;a href="https://github.com/ardatan/graphql-toolkit"&gt;GraphQL-Toolkit&lt;/a&gt;, &lt;a href="https://github.com/urigo/graphql-modules"&gt;GraphQL Modules&lt;/a&gt;, &lt;a href="https://github.com/kamilkisiela/graphql-inspector"&gt;GraphQL Inspector&lt;/a&gt; and &lt;a href="https://graphql-code-generator.com/"&gt;graphql-code-generator&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is a continuation of making order in the schema management tools across the ecosystem&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you are at GraphQL-Conf this week, come say hi&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/urigo/merge-graphql-schemas"&gt;merge-graphql-schemas&lt;/a&gt; is a popular library in the GraphQL Ecosystem.&lt;/p&gt;

&lt;p&gt;It’s one of the first tools people encounter once they went through their first GraphQL implementation and start to wonder how to organize their GraphQL server code.&lt;/p&gt;

&lt;p&gt;The OK-Grow! Team has been maintaining that library for years, filling a needed gap in the ecosystem.&lt;/p&gt;

&lt;p&gt;At the same time, &lt;a href="https://github.com/the-guild-org"&gt;The Guild&lt;/a&gt; has been working on &lt;a href="https://github.com/the-guild-org/Stack"&gt;similar tools&lt;/a&gt; around GraphQL schema and module management.&lt;/p&gt;

&lt;p&gt;Today we are happy to announce that we are joining forces and merging our efforts to create open source, easy and scalable solutions for GraphQL servers.&lt;/p&gt;

&lt;p&gt;In a couple of days of work we’ve refactored the underlying implementation of &lt;a href="https://github.com/urigo/merge-graphql-schemas"&gt;merge-graphql-schemas&lt;/a&gt; to use &lt;a href="https://github.com/ardatan/graphql-toolkit"&gt;GraphQL-Toolkit&lt;/a&gt; under the hood, we can close around 90% of the open issues on the library while making sure all existing tests are passing!&lt;/p&gt;

&lt;p&gt;We are happy to announce a new beta release (1.6.0-beta) is out!&lt;/p&gt;

&lt;p&gt;If you are a user of &lt;a href="https://github.com/urigo/merge-graphql-schemas"&gt;merge-graphql-schemas&lt;/a&gt; please give the new version a try before we make a full release.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add merge-graphql-schemas@next
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  What’s next?
&lt;/h1&gt;

&lt;p&gt;The Guild has been busy for a while creating scalable GraphQL solutions around schema and modules management for large teams.&lt;/p&gt;

&lt;p&gt;The main issue we see today in the ecosystem is that there is no clear overview of which tools solve which problem area.&lt;/p&gt;

&lt;p&gt;In order to make sure we solve the right issues in the right place, we need clear boundaries between the different libraries and solutions.&lt;/p&gt;

&lt;p&gt;Let’s try to break down the different areas of solutions needed when splitting GraphQL schemas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Building and executing GraphQL according to spec — &lt;strong&gt;The Engine&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Structuring multiple building blocks of the same server into a single executable schema — &lt;strong&gt;GraphQL Tools and Frameworks&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Structuring multiple servers instances into a single executable schema — &lt;strong&gt;Federation&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we can gather all use cases from the community, put them as tests on the right library and make sure we solve each one of them.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Engine
&lt;/h1&gt;

&lt;p&gt;The Engine (in the Javascript world the most popular one is &lt;a href="https://github.com/graphql/graphql-js"&gt;graphql.js&lt;/a&gt;) should be responsible of taking a ready schema and resolvers, validate the objects, introspecting them and executing documents against them at runtime.&lt;/p&gt;

&lt;p&gt;That GraphQLSchema input must be strictly valid according to the GraphQL Spec.&lt;/p&gt;

&lt;p&gt;That’s why manipulating a ready GraphQLSchema object can be hard. GraphQLSchema object should be the final object to input the engine.&lt;/p&gt;

&lt;p&gt;The Engine should not care or help you create that final schema or resolvers.&lt;/p&gt;

&lt;h1&gt;
  
  
  GraphQL Management Tooling
&lt;/h1&gt;

&lt;p&gt;We can think of the Engine like a Web Browser — It is responsible of taking a spec (Javascript and HTML) and execute it in a consistent way.&lt;/p&gt;

&lt;p&gt;But the browser doesn’t care about how you create that Javascript and HTML bundle.&lt;/p&gt;

&lt;p&gt;That means that like we use babel, Typescript or frameworks for manipulating code to generate spec-compliant output, we can do the same for GraphQL with &lt;a href="https://github.com/graphql/graphql-js"&gt;graphql.js&lt;/a&gt; as our target “browser”.&lt;/p&gt;

&lt;p&gt;Those tools should help you organize and manage your code in your preferred way, without needing to be bound by what &lt;a href="https://github.com/graphql/graphql-js"&gt;graphql.js&lt;/a&gt; expects.&lt;/p&gt;

&lt;p&gt;One of the main things that those tools can provide us is an easy way to split the code and the schema into small chunks and later merge them with different merging strategies.&lt;/p&gt;

&lt;p&gt;Just like Javascript frameworks, using those tools can get you very far and make it easy to handle huge codebases with many different teams.&lt;/p&gt;

&lt;h1&gt;
  
  
  Federation
&lt;/h1&gt;

&lt;p&gt;In some scenarios you would want to run completely different servers and merge them somehow into a single GraphQL gateway.&lt;/p&gt;

&lt;p&gt;Schema stitching and &lt;a href="https://www.apollographql.com/docs/apollo-server/federation/federation-spec/"&gt;schema federation&lt;/a&gt; are attempts to make that work less manual.&lt;/p&gt;

&lt;p&gt;There are some use cases where you might want those types of solutions, but they also add a lot of complexity so it’s important to understand very well why you really can’t handle your use case in a build-tool type of solution, and to know if Federation is an end goal or a stepping point to get you further.&lt;/p&gt;

&lt;h1&gt;
  
  
  Breaking it all down
&lt;/h1&gt;

&lt;p&gt;After years of working with GraphQL, from small applications to managing schemas across huge corporations, creating open source tools and best practices around those, we want to share it all with the community.&lt;/p&gt;

&lt;p&gt;In the next few weeks we will publish articles about each solution type, the tools around and when you should use what.&lt;/p&gt;

&lt;p&gt;Things like why you should split your schemas, why not, what are the existing solutions out there and when to use each one.&lt;/p&gt;

&lt;p&gt;We will also add examples of all those use cases into our &lt;a href="https://www.tortilla.academy/Urigo/WhatsApp-Clone-Tutorial/"&gt;main tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We need you to send us your questions, use cases and ideas — we want to make sure we cover as many use cases as possible across our libraries and other libraries we &lt;a href="https://github.com/apollographql/graphql-tools/pull/1150"&gt;contribute too&lt;/a&gt; as well (some things might fit into graphql.js or Apollo for example).&lt;/p&gt;

&lt;p&gt;You can comment here or submit issues into any of &lt;a href="https://github.com/the-guild-org/Stack"&gt;our repositories&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Thank you OK-Grow!
&lt;/h1&gt;

&lt;p&gt;I want to personally thank the OK-Grow! Team and specifically Paul for being a very early adopter and supporter of the GraphQL community.&lt;/p&gt;

&lt;p&gt;The work you have done so far has been amazing and valuable and we are dedicated to continue to support our community in the best way possible.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Sofa — The best way to REST (is GraphQL)</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:14 +0000</pubDate>
      <link>https://dev.to/urigo/sofa-the-best-way-to-rest-is-graphql-5e44</link>
      <guid>https://dev.to/urigo/sofa-the-best-way-to-rest-is-graphql-5e44</guid>
      <description>&lt;h2&gt;
  
  
  Ending the REST vs GraphQL debate once and for all
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r5jPCVbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AImnnfwJEdDIH3CtV2-U98A.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r5jPCVbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AImnnfwJEdDIH3CtV2-U98A.gif%3Fraw%3Dtrue" alt="" title="Activate REST API in a snap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Don’t choose between REST and GraphQL — &lt;strong&gt;create a fully RESTful API automatically&lt;/strong&gt; from your GraphQL implementation (with a library and a single line of code)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get most of &lt;strong&gt;the benefits of GraphQL&lt;/strong&gt; on the backend and frontend, while using and &lt;strong&gt;exposing REST&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Support all your existing clients&lt;/strong&gt; with REST while improving your backend stack with GraphQL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create custom, perfectly client-aligned REST endpoints for your frontend simply by naming a route and attaching a query&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stop arguing about REST vs GraphQL. Use GraphQL, generate REST and get the best from both&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the other way around (REST to GraphQL) you won’t get the best of both world but less powerful, harder to maintain server implementation with some of the benefits of GraphQL. It is a good and fast start for a migration though..&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Wait, WHAT!?
&lt;/h1&gt;

&lt;p&gt;Many articles have been written about the pros and cons of GraphQL and REST APIs and how to decide which one to use. I’m not going to repeat those here..&lt;/p&gt;

&lt;p&gt;A lot of time and energy spent by smart consultants to write those articles, read those articles, while most of them are finished with the “it depends on your use case” summary, without actually specifying those use cases!&lt;/p&gt;

&lt;p&gt;I’ve been working with REST, GraphQL and SOAP APIs for many years. So I thought, why not come up with a list of those use cases and for each one of those to check — what can’t you do in GraphQL that you can do with REST and what you wouldn’t want to do with GraphQL and you would prefer REST.&lt;/p&gt;

&lt;p&gt;After creating that list, I suddenly had a thought — what if there was another option — what if my powerful GraphQL server could just generate a REST API for me?&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Then I could get the best of both worlds!
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;The more I dived into the idea and implementation then more I realized it’s not only that we can have both types of APIs created for us, but even if we just want to expose REST APIs, and none of our clients use GraphQL, &lt;strong&gt;GraphQL is the best way the create REST APIs!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does the above sentence even make sense?!
&lt;/h2&gt;

&lt;p&gt;Usually when we (&lt;a href="https://medium.com/the-guild"&gt;The Guild&lt;/a&gt;) help companies and organizations to modernize their APIs, the first to understand the benefits of GraphQL are the frontend developers, for obvious reasons. But as soon as the backend developers “Get it”, they become the biggest advocates of the technology. But they still need to support existing clients and 3rd party partners.&lt;/p&gt;

&lt;p&gt;That’s why those newly generated REST APIs get a lot of the features and benefits from the internal GraphQL implementation that make backend developers happy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Fully &lt;strong&gt;generated documentation&lt;/strong&gt; that is always up-to-date (Swagger, OpenAPI and GraphiQL)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Truly &lt;strong&gt;RESTful API&lt;/strong&gt; out of the box&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;GraphQL Subscriptions as Webhooks&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Runtime validation of data&lt;/strong&gt; — be 100% sure that fetched data matches schema’s and query’s structure. You send exactly what I want to send, string is a string, an object has exactly the same properties.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating a custom endpoint is now a matter of choose a route name and attaching a query to it. done. &lt;strong&gt;No more manual work of creating and maintaining client specific endpoints!&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use GraphQL’s philosophy of evolving APIs through schemas — &lt;strong&gt;no more painful V1 — V2 API migrations.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use modern technology that is easier to hire people to. Companies like Facebook, Airbnb and &lt;a href="https://graphql.org/users/"&gt;others&lt;/a&gt; have moved to GraphQL. None of them has gone back.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The power of GraphQL resolvers&lt;/strong&gt; to create your API implementation, instead of manually written controllers from MVC&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I get from having resolvers?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Easier to transform data so it matches the response (GraphQL Schema). That’s because every entity has its own resolvers, so the mapping is moved into smaller pieces and reused across an entire app.&lt;/li&gt;
&lt;li&gt;  GraphQL allows you to easily share data across every resolver, we call it Context.&lt;/li&gt;
&lt;li&gt;  Forces you to define and resolve data in an opinionated way that actually helps building an API. It runs functions in parallel (functions that are nested at the same level), handles async and at the end, it is responsible of merging all of that into a single object, so you don’t have to think about it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Sofa — Use GraphQL to create RESTful APIs
&lt;/h1&gt;

&lt;p&gt;So we created &lt;a href="https://github.com/Urigo/SOFA"&gt;Sofa&lt;/a&gt; (pun intended), an open source library you install on your GraphQL server to create a fully RESTful and configurable API gateway. Use GraphQL to REST.&lt;/p&gt;

&lt;h2&gt;
  
  
  “How to” tutorial
&lt;/h2&gt;

&lt;p&gt;Let’s create a short step by step tutorial on how to create a RESTful API.&lt;/p&gt;

&lt;p&gt;Step 1: npm install the &lt;code&gt;[sofa-api](https://www.npmjs.com/package/sofa-api)\&lt;/code&gt; package and add the following line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sofa&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sofa-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;sofa&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Step 2: Go REST on a Sofa, you’re done.&lt;/p&gt;

&lt;p&gt;Kamil Kisiela added Sofa to the &lt;a href="https://medium.com/open-graphql/migrating-spacex-api-to-graphql-e1fe69a3a8e7"&gt;SpaceX GraphQL API&lt;/a&gt; implementation by Carlos Rufo, &lt;strong&gt;in a single &lt;a href="https://github.com/spacexland/api/pull/7/commits/9b50393ad33c27693d89f271ec1247715c6dcc53#diff-f41e9d04a45c83f3b6f6e630f10117fe"&gt;commit&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Check out the fully generated &lt;a href="https://api.spacex.land/rest/capsules"&gt;REST endpoints&lt;/a&gt;, the &lt;a href="https://api.spacex.land/rest/"&gt;Swagger live documentation&lt;/a&gt;, &lt;a href="https://api.spacex.land/graphql"&gt;GraphiQL editor&lt;/a&gt; and the &lt;a href="https://api.spacex.land/"&gt;GraphiQL-Explorer&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;By the way, what you see here is a REST API, generated on top of a GraphQL API, created on top of another REST API….&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Why did you do that for!?!?
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Gradually migrating from old REST implementations
&lt;/h2&gt;

&lt;p&gt;This is actually a good direction to go. In many of the companies we work with, they’ve created REST API layers using old technology on top of their original web-services.&lt;/p&gt;

&lt;p&gt;But those REST implementations are problematic (for all the obvious reasons people choose to move to GraphQL).&lt;/p&gt;

&lt;p&gt;So our way to go is to create GraphQL implementations on top of those REST layers, migrate the clients to those implementations and then gradually remove the old RESTful layer and call the services directly.&lt;/p&gt;

&lt;p&gt;Using Sofa made those transitions much faster because we can offer all the existing clients to migrate to our GraphQL implementation without actually using GraphQL themselves. We simply expose the same REST endpoints on top of GraphQL and they are moving to our layer happily because we can accommodate all of their requests and custom REST endpoints much faster than the original, old REST implementations.&lt;/p&gt;




&lt;h1&gt;
  
  
  Give me more details
&lt;/h1&gt;

&lt;p&gt;Sofa uses Express by default but you can use any other server framework. Sofa is also GraphQL server implementation agnostic.&lt;/p&gt;

&lt;p&gt;Head over to the &lt;a href="https://sofa-api.com"&gt;Sofa website&lt;/a&gt; for documentation and to the &lt;a href="https://github.com/Urigo/sofa"&gt;Github repository&lt;/a&gt; for reporting issues and helping out.&lt;/p&gt;

&lt;h1&gt;
  
  
  How Sofa works?
&lt;/h1&gt;

&lt;p&gt;Under the hood, Sofa turns each field of Query and Mutation types into routes. First group of routes is available only through GET method, mutations on the other hand get POST.&lt;/p&gt;

&lt;p&gt;Sofa uses GraphQL’s AST to create an operation with all possible variables (even those deeply nested) and knows exactly what to fetch. Later on it converts the request’s body into operation’s variables and execute it against the Schema. It happens locally, but it’s also possible to use an external GraphQL Server or even Apollo Link.&lt;/p&gt;

&lt;p&gt;Right now Sofa has a built-in support for &lt;a href="https://expressjs.com"&gt;Express&lt;/a&gt; but it’s totally possible to use a different framework. The main concept stays exactly the same so only the way we handle the request differs across different server implementations.&lt;/p&gt;

&lt;h2&gt;
  
  
  GraphQL Subscriptions as Webhooks?
&lt;/h2&gt;

&lt;p&gt;The way it works is simply, you start a subscription by calling a special route and you get a unique ID that later on might be used to update or even stop the subscription. Subscriptions are Webhooks. Sofa knows exactly when there’s an even happening on your API and notifies you through the endpoint you’ve assigned a subscription to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Models / Resources?
&lt;/h2&gt;

&lt;p&gt;In some cases you don’t want to expose an entire object but just its id. How you’re able to do that with Sofa? You need to have two queries. First one has to return a single entity based just on its id (which would be an argument) and the second one should resolve a list of those. Also the names should match, for example a resource called User should have two queries: &lt;code&gt;user(id: ID): User&lt;/code&gt; and &lt;code&gt;users: [User]&lt;/code&gt;. Pretty much the same thing you would do with REST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {
  user(id: ID!): User
  users: [User]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Before Sofa creates the routes, it looks for those Models and registers them so when the operations are built you don’t fetch everything but only an id.&lt;/p&gt;

&lt;p&gt;But what if you want to fetch an entire object but only in few places?&lt;/p&gt;

&lt;p&gt;There’s an option called &lt;code&gt;ignore&lt;/code&gt; that allows you to do that. You simply pass a path in which you want to overwrite the default behavior.&lt;/p&gt;

&lt;p&gt;Given the schema below, you would get just author’s id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Book {
  id: ID
  title: String!
  author: User!
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extend type Query {
  book(id: ID!): Book
  books: [Book]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;ignore: ['Book.author']&lt;/code&gt;you end up with an entire User object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sofa({
  ...,
  ignore: ['Book.author'],
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Swagger and OpenAPI
&lt;/h2&gt;

&lt;p&gt;Thanks to GraphQL’s type system Sofa is able to generate always up-to-date documentation for your REST API. Right now we support Swagger and its OpenAPI specification but it’s really easy to adopt different specs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sofa&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;OpenAPI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sofa-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;OpenAPI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;info&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Example API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;sofa&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;onRoute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;openApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addRoute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;basePath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;openApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./swagger.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/Urigo/sofa"&gt;sofa-api&lt;/a&gt; makes it extremely easy to create a RESTful API with all the best practices of REST from a GraphQL server using all its power.&lt;/p&gt;

&lt;p&gt;Stop wasting your life arguing about REST vs GraphQL — Be productive, get the benefits of both worlds and move into the future of API development.&lt;/p&gt;

&lt;p&gt;I hope this would become the last REST vs. GraphQL article out there…. if you think it won’t, comment with a use case and let’s try it out!&lt;/p&gt;

&lt;p&gt;Thanks to Kamil Kisiela for working with me on this and making this library a reality!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Follow us on &lt;a href="https://github.com/urigo/sofa"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://medium.com/the-guild"&gt;&lt;strong&gt;Medium&lt;/strong&gt;&lt;/a&gt;, we are planning to release many more posts in the next couple of weeks about what we’ve learned using &lt;strong&gt;GraphQL&lt;/strong&gt; in recent years.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Rewriting angular-meteor.com in Angular Universal</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:13 +0000</pubDate>
      <link>https://dev.to/urigo/rewriting-angular-meteor-com-in-angular-universal-2hj8</link>
      <guid>https://dev.to/urigo/rewriting-angular-meteor-com-in-angular-universal-2hj8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QKiWK5A1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AChqVouqofNoSwmgp_-Ytag.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QKiWK5A1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AChqVouqofNoSwmgp_-Ytag.png%3Fraw%3Dtrue" alt="" title="angular-meteor.com is now a universal app!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We recently finished re-writing and deploying our new &lt;a href="https://angular-meteor.com/"&gt;angular-meteor.com&lt;/a&gt; website with completely new tooling using Angular Universal and our new tutorial infrastructure.&lt;/p&gt;

&lt;p&gt;In this post, I’ll share our experience using Angular Universal, and introduce the tools that we created on top of it. We’ll write about (and open source) our new tutorial infrastructure in a following post, so stay tuned!&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Our former website was a dynamic app. We wanted to rewrite it into a static website because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; It needed a server and hosting.&lt;/li&gt;
&lt;li&gt; We needed a lot of tooling in order to make it SEO compatible.&lt;/li&gt;
&lt;li&gt; It loaded slowly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;We’re happy to say… The transition was successful!&lt;/strong&gt; Check it out and take a look at the new tutorials &lt;a href="https://angular-meteor.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are the improvements this made possible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The page loads much faster&lt;/li&gt;
&lt;li&gt;  No need for servers anymore, we use GitHub Pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To accomplish this, we created a tool that takes various content types and renders it to any format we want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Input sources — A unique markdown format for our tutorials and a JSDoc format.&lt;/li&gt;
&lt;li&gt;  Render targets — Our angular-meteor.com website, your own website or doc format, or a Medium post API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Converting input sources to render outputs
&lt;/h1&gt;

&lt;p&gt;Our new tooling is capable of getting input sources from various content types and generating output in any format we like. Currently, we published it as a package, which includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Accepting &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/steps-templates-loader.ts#L28-L42"&gt;Markdown&lt;/a&gt; + &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/tutorials-registry-cache.ts#L54-L85"&gt;Git patch&lt;/a&gt; from our tutorial infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Accepting &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/api-load-resolve.ts#L20-L78"&gt;JSDoc&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Angular 2 &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/diffbox.component.ts"&gt;Components&lt;/a&gt; and &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/tutorial-navigation.component.ts"&gt;Directives&lt;/a&gt;, and some utils functions that relate to Angular 2, including &lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/tutorial-routes.ts"&gt;tutorial -&amp;gt; route&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/Urigo/tutorial-infrastructure/blob/master/src/generate-static.ts"&gt;Static website generator&lt;/a&gt; — think about this as a NgModule to HTML files converter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Tutorial as input
&lt;/h1&gt;

&lt;p&gt;As part of the rewrite, we created a new tutorial infrastructure that we’ll talk about in a future post when we release a few more features. You can see it in action here — &lt;a href="https://angular-meteor.com/tutorials/whatsapp2/ionic/setup"&gt;https://angular-meteor.com/tutorials/whatsapp2/ionic/setup&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the purpose of this post, the important thing to know about the infrastructure is that the code examples are being generated from a real app using real commits (inspired by Sashko Stubailo’s work &lt;a href="https://blog.meteor.com/building-maintainable-step-by-step-tutorials-with-git-cdb6d77ea966#.lg32xh4c9"&gt;on the Meteor tutorial&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The infrastructure renders markdown files with links to the git commits, and we need to turn those into a diff-box components with the actual code that changed in the commit, like &lt;a href="https://angular-meteor.com/tutorials/whatsapp2/ionic/meteor-server-side#collections"&gt;here&lt;/a&gt; for example.&lt;/p&gt;

&lt;h1&gt;
  
  
  JSDoc as input
&lt;/h1&gt;

&lt;p&gt;Let’s start again with the result of this section, so it will be simpler to understand: &lt;a href="https://angular-meteor.com/api/angular2-meteor/latest/Meteor-RxJS"&gt;https://angular-meteor.com/api/angular2-meteor/latest/Meteor-RxJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We want to use the JSDoc standard over our code (&lt;a href="https://github.com/Urigo/meteor-rxjs/blob/master/src/MeteorObservable.ts#L13-L24"&gt;example&lt;/a&gt;), take this JSDoc definition, convert it into a standard markdown file, display it in our website, and finally expose it directly inside the repository of the package (&lt;a href="https://github.com/Urigo/meteor-rxjs/blob/master/docs/ObservableCollection.md"&gt;example&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;We wanted versioning because our API might change over time — that’s where Git comes to our aid. We also have a Git revision (commit id or tag) for each version of the package. That way, we can take a specific version of the file with it’s documentation from GitHub and generate the API reference for all of versions of the package and API docs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components, Directives, and utils
&lt;/h1&gt;

&lt;p&gt;The Angular 2 components and directives are meant to display results of the markdown docs together with the special Git patch handlers. This means it’s using a regular markdown parser with the small addition of DiffBox, a Component we wrote that displays the changes in each commit in a diff format (just like a diff view in GitHub).&lt;/p&gt;

&lt;p&gt;Also, we have directives that are useful for: navigation, creating links, displaying a list of steps of the tutorial, links to download those steps (based on git commit) and more.&lt;/p&gt;

&lt;p&gt;We also have a route generator for the tutorial, which means that, based on your tutorial definition, this util will generate your routes for the Angular router with all the required resolve phase that the infrastructure needs (load files from GitHub, format, convert and so on).&lt;/p&gt;

&lt;h1&gt;
  
  
  Static HTML Generator
&lt;/h1&gt;

&lt;p&gt;Our main output is our &lt;a href="https://angular-meteor.com/"&gt;angular-meteor.com&lt;/a&gt; website. The utils wrap the sources with a beautiful design, custom pages and stylesheet, and then uses the last part of the infrastructure — the static page generator.&lt;/p&gt;

&lt;p&gt;Using your application’s route definition (the generated tutorial routes, along with the custom pages you need), this tool loads the entire page (generated on the server side as we’re running in an Angular Universal environment) and saves it into a single HTML file that has no dependencies at all. The whole page is inside a single HTML file — no JS and no external CSS files!&lt;/p&gt;

&lt;p&gt;Our next step is the deployment of this website, which is easy, because we are using an autonomous HTML files that every single HTTP server can serve. We chose GitHub Pages to host our website, so we don’t need any external server or hosting.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Result
&lt;/h1&gt;

&lt;p&gt;We managed to accomplish all of our goals for the new website:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We met our own needs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  It’s easy to maintain because it uses the same GitHub repository that stores the actual tutorial code.&lt;/li&gt;
&lt;li&gt;  It’s super fast and because it loads only static HTML files.&lt;/li&gt;
&lt;li&gt;  Its hosting is simple (GitHub Pages) and it has no server-side at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;We created something that might be useful for others:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Extensions to Angular Universal that can accept your own inputs and outputs.&lt;/li&gt;
&lt;li&gt;  Tools for rendering markdown from remote source with Angular Universal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check out the website and code! Maybe you can find some utils for generating routes of API docs, or expose Components and Directives that you can use later to enrich your own website.&lt;/p&gt;

&lt;p&gt;We saw that the Angular team has started working on a new angular.io implementation and would love to help with our tools and experiences from doing very similar work on our own website.&lt;/p&gt;

&lt;p&gt;Most importantly — enjoy the new &lt;a href="https://angular-meteor.com/"&gt;angular-meteor.com&lt;/a&gt; :)&lt;/p&gt;

&lt;h1&gt;
  
  
  Next steps for Angular-Meteor
&lt;/h1&gt;

&lt;p&gt;In recent months, both Meteor and Angular have made huge leaps, so we have a lot of goodies to catch up on.&lt;/p&gt;

&lt;p&gt;Our vision for the next version of Angular Meteor includes the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Support for Angular CLI with &lt;a href="https://blog.meteor.com/leverage-the-power-of-meteor-with-any-client-side-framework-bfb909141008"&gt;Meteor Client Bundler&lt;/a&gt; (already works).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The easiest way to do lazy load in Angular with &lt;a href="https://blog.meteor.com/dynamic-imports-in-meteor-1-5-c6130419c3cd"&gt;Meteor 1.5 (code splitting and dynamic imports without configuration)&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AOT out of the box.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But we want your help! If you’re interested in helping us tackle these exciting features, &lt;a href="https://github.com/urigo"&gt;contact us directly!&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Use Subscriptions in GraphiQL</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:13 +0000</pubDate>
      <link>https://dev.to/urigo/how-to-use-subscriptions-in-graphiql-2kog</link>
      <guid>https://dev.to/urigo/how-to-use-subscriptions-in-graphiql-2kog</guid>
      <description>&lt;h2&gt;
  
  
  Easily test GraphQL subscriptions from your browser
&lt;/h2&gt;

&lt;p&gt;There has been a lot of buzz about GraphQL Subscriptions in the community recently, and a lot of people are excited about the &lt;a href="https://dev-blog.apollodata.com/the-next-step-for-realtime-data-in-graphql-b564b72eb07b#.w9zvvcjbh"&gt;subscriptions RFC&lt;/a&gt; opened by Rob Zhu from Facebook.&lt;/p&gt;

&lt;p&gt;If you haven’t tried GraphQL subscriptions yet, check out our docs to learn how to &lt;a href="http://dev.apollodata.com/tools/graphql-subscriptions/index.html"&gt;add subscriptions to your existing Node.js GraphQL server&lt;/a&gt;. You can also easily try building a React app with them by following &lt;a href="https://www.graph.cool/docs/tutorials/worldchat-subscriptions-example-ui0eizishe/"&gt;Graphcool’s tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today, I want to tell you about something else that’s really cool: &lt;strong&gt;Did you know that &lt;a href="https://github.com/graphql/graphiql"&gt;Graph_i_QL&lt;/a&gt; already supports subscriptions today?&lt;/strong&gt; Don’t believe me? Here’s a demo so you can see for yourself:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=aAwZrBgmnho"&gt;https://www.youtube.com/watch?v=aAwZrBgmnho&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check out the working example of GitHunt with Graph*&lt;em&gt;i&lt;/em&gt;*QL &lt;a href="https://github.com/apollographql/githunt-API"&gt;here&lt;/a&gt; (and the React frontend &lt;a href="http://github.com/apollographql/githunt-react"&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The standard GraphiQL library already supports passing in a fetcher that returns an observable &lt;em&gt;or&lt;/em&gt; promise. That means that anyone can configure it with their own transport, even if it supports multiple results. We’ve already done that for you, using a new&lt;a href="https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher"&gt;&lt;code&gt;graphql-subscriptions-fetcher&lt;/code&gt;&lt;/a&gt;, so you don’t have to.&lt;/p&gt;

&lt;p&gt;The following steps are all you need to do. (We’re using &lt;code&gt;graphql-server-express&lt;/code&gt; for the example.)&lt;/p&gt;

&lt;p&gt;First, make sure you have the latest &lt;code&gt;graphql-server-express&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install —-save graphql-server-express
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, all you need to do is to set a new field we added to &lt;code&gt;graphqlExpress&lt;/code&gt; config, called &lt;code&gt;subscriptionsEndpoint&lt;/code&gt;, with the Websocket URL subscriptions endpoint (this is the same endpoint you use in your &lt;code&gt;SubscriptionClient&lt;/code&gt;). For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(‘/graphiql’, graphiqlExpress({
  endpointURL: ‘/graphql’,
  subscriptionsEndpoint: `ws://localhost:3000/subscriptions`,
}));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s it! Finally, all you have to do is start your server, open your browser in &lt;a href="http://api.githunt.com/graphiql"&gt;http://localhost:3000/graph_i_ql&lt;/a&gt;, write a GraphQL subscriptions query inside, and the published data from the server will be pushed into your Graph_i_QL client and displayed in the result screen of Graph_i_QL.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This example uses GraphQL server with express — but it also works with graphql-server-hapi, Koa, Restify and Lambda. Just add the &lt;code&gt;_subscriptionsEndpoint_&lt;/code&gt; field to your GraphiQL configuration and you are good to go! You can also check out the live GitHunt example &lt;a href="http://api.githunt.com/graphiql"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What if you don’t use &lt;a href="http://dev.apollodata.com/tools/graphql-server/index.html"&gt;graphql-server&lt;/a&gt;?
&lt;/h2&gt;

&lt;p&gt;We added the new Graph_i_QL subscriptions support to &lt;a href="http://dev.apollodata.com/tools/graphql-server/index.html"&gt;graphql-server&lt;/a&gt; by default, but in case you’re not using it, it’s still very easy to add that support to your own server.&lt;/p&gt;

&lt;p&gt;Graph_i_QL is usually served as static HTML (&lt;a href="https://github.com/apollographql/graphql-server/blob/master/packages/graphql-server-module-graphiql/src/renderGraphiQL.ts#L39"&gt;here’s how we do it in graphql-server&lt;/a&gt;), so first you need to load &lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;&lt;code&gt;subscriptions-transport-ws&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher"&gt;&lt;code&gt;graphql-subscriptions-fetcher&lt;/code&gt;&lt;/a&gt;  inside the tag. We’ve published the transport client so that it’s easy to use in a script tag from &lt;a href="https://unpkg.com/"&gt;Unpkg&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src=”//unpkg.com/subscriptions-transport-ws@0.5.4/browser/client.js”&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, you need to create a &lt;code&gt;SubscriptionClient&lt;/code&gt; with your subscriptions endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(‘YOUR_SUBSCRIPTIONS_ENDPOINT_HERE’, { reconnect: true });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var subscriptionsFetcher = window.SubscriptionsTransportWs.graphQLFetcher(subscriptionsClient, graphQLFetcher);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, replace the regular &lt;code&gt;graphqlFetcher&lt;/code&gt; you use in Graph_i_QL with the one that uses the fetcher from &lt;a href="https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher"&gt;&lt;code&gt;graphql-subscriptions-fetcher&lt;/code&gt;&lt;/a&gt;  when creating your Graph_i_QL instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReactDOM.render(
  React.createElement(GraphiQL, {
    fetcher: subscriptionsFetcher,
    onEditQuery: onEditQuery,
    onEditVariables: onEditVariables,
    onEditOperationName: onEditOperationName,
    query: ${safeSerialize(queryString)},
    response: ${safeSerialize(resultString)},
    variables: ${safeSerialize(variablesString)},
    operationName: ${safeSerialize(operationName)},
}), document.body);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/urigo/graphql-server/blob/feat/subscriptions-graphiql/packages/graphql-server-module-graphiql/src/renderGraphiQL.ts"&gt;Here&lt;/a&gt; is a complete example of how it should look.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s happening behind the scenes?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/apollographql/subscriptions-transport-ws"&gt;&lt;code&gt;subscriptions-transport-ws&lt;/code&gt;&lt;/a&gt;is a GraphQL subscriptions network transport. Loading it into Graph_i_QL client and replacing the &lt;code&gt;graphQLFetcher&lt;/code&gt; function with &lt;a href="https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher"&gt;&lt;code&gt;graphql-subscriptions-fetcher&lt;/code&gt;&lt;/a&gt;’s fetcher will give you a plug-and-play solution for live-stream subscriptions into your app’s Graph_i_QL editor!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that we are still using the original &lt;code&gt;_graphQLFetcher_&lt;/code&gt; inside the new fetcher. We fall back to the original for GraphQL operations that aren’t subscriptions (queries and mutations).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Try it today!
&lt;/h2&gt;

&lt;p&gt;Even though GraphQL subscriptions are still at the RFC stage, it is already being used by many companies in production, and the libraries and tools have been evolving to support a wide range of use cases. So try GraphQL subscriptions in order to add real time ability to your apps today!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S3kvKFwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AtVIRc087V_7VlSs46TwlYQ.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S3kvKFwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AtVIRc087V_7VlSs46TwlYQ.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Leverage the power of Meteor with any client-side framework</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:12 +0000</pubDate>
      <link>https://dev.to/urigo/leverage-the-power-of-meteor-with-any-client-side-framework-34fm</link>
      <guid>https://dev.to/urigo/leverage-the-power-of-meteor-with-any-client-side-framework-34fm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to Meteor-Client-Bundler
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3aVyV6X5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ACKGGtcy7rgOwCQ-mAFmw0g.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3aVyV6X5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ACKGGtcy7rgOwCQ-mAFmw0g.png%3Fraw%3Dtrue" alt="" title="Meteor Javascript Client bundle can run on any frontend app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Meteor was first released back in 2011, and since then it’s been one of the most powerful platforms for web developers. It brought many new concepts to the table — one of the more powerful ones is where the client, server and the database can share code, almost the same API and code snippets, which really accelerated the development process.&lt;/p&gt;

&lt;p&gt;This has been a very big advantage that’s proven itself to be worthy, but has also created a misconception that Meteor is a monolith that can’t be broken down to smaller parts. But in fact, when you build a Meteor app for deployment to &lt;a href="https://www.meteor.com/hosting"&gt;Galaxy&lt;/a&gt; or any other hosting platform, Meteor essentially generates a stand-alone Node application that you can run anywhere Node is installed. This built application can be easily consumed by a wide variety other tools that work with Node and Javascript apps.&lt;/p&gt;

&lt;p&gt;In this post, I will show how you can use your existing React, Angular, or WebPack front-end app (or break up your existing Meteor front-end app away from the Meteor CLI) while still using Meteor’s benefits like Meteor Collections, Minimongo, real time updates and DDP, accounts packages and more…&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing Meteor Client Bundler
&lt;/h2&gt;

&lt;p&gt;Two example scenarios could be: a) We want to use React Native’s CLI to build our client, since it provides us with native mobile components, and a configurable bundler; or b) We want to use WebPack and the great &lt;a href="https://github.com/facebookincubator/create-react-app"&gt;create-react-app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Because we’re using Meteor, you might think we’re obligated to use the Meteor CLI, leaving WebPack’s great tools impractical to use. We can therefore ask the following question: “Is there a way to use WebPack, or any other similar tool, to create our client, and Meteor as our backend?” Well folks, the answer is — YES!&lt;/p&gt;

&lt;p&gt;I present you — &lt;a href="https://github.com/Urigo/meteor-client-bundler"&gt;&lt;strong&gt;Meteor Client Bundler&lt;/strong&gt;&lt;/a&gt; (it’s a long name, so we’re gonna refer it as &lt;strong&gt;MCB&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MCB&lt;/strong&gt;, as we can infer, is a module-bundler which will take a bunch of Meteor packages and bundle them into a single script, based on a specified configuration. This means we can load Meteor’s core client-script, along with other desired packages, like &lt;code&gt;mys:accounts-phone&lt;/code&gt;, &lt;code&gt;jalik:ufs&lt;/code&gt;, &lt;code&gt;matb33:collection-hooks&lt;/code&gt; etc into any front-end app!&lt;/p&gt;

&lt;p&gt;This will give us the ability to create two separate projects: one is made with WebPack CLI (the client) and other is made with Meteor’s CLI (the server). Furthermore, with a little help from bundling tools like Webpack, we can even achieve the effect of shared code snippets between the two apps, which will be shown further in this article.&lt;/p&gt;

&lt;p&gt;Some of the advantages of such a strategy are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Applications which are not based on Meteor can use the DDP client to fetch data from a Meteor-service&lt;/li&gt;
&lt;li&gt;  We can gradually migrate outdated front-end applications into Meteor&lt;/li&gt;
&lt;li&gt;  We can use other CLI tools besides Meteor’s like WebPack, Angular and Ionic CLIs and more and not be locked in on a single CLI&lt;/li&gt;
&lt;li&gt;  Use Meteor when and where it excels and where it fits your needs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I believe that through practical example you can get the hang of it and understand exactly what I’m talking about, by simply fulfilling the scenario described in the second paragraph.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Let’s dive in! We will begin with creating our client using &lt;a href="https://github.com/facebookincubator/create-react-app"&gt;create-react-app&lt;/a&gt;, by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ create-react-app my-frontend-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, we will create a web API service using Meteor’s CLI by typing the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor create api
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that they are both created, Let’s connect them to each other, so the React client will know how to use Meteor collections and retrieve data from them using MCB.&lt;/p&gt;

&lt;p&gt;First, you’ll need to install MCB globally using NPM using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install -g meteor-client-bundler
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will make MCB available globally as a CLI under the name &lt;code&gt;meteor-client&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor-client — help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks to MCB, we can create a Meteor client with all the necessary dependencies in it using the &lt;code&gt;bundle&lt;/code&gt; command. The &lt;code&gt;bundle&lt;/code&gt; command takes a configuration file and can be operated differently. The easiest and fastest solution would be providing it the path where the Meteor server is at, using the &lt;code&gt;-s, — source&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor-client bundle — source=api
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will create a new file called &lt;code&gt;meteor-client.js&lt;/code&gt; under the directory &lt;code&gt;node_modules&lt;/code&gt;, which can easily be loaded anywhere in the project like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import “meteor-client”;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you want, you can change the output destination by providing a &lt;code&gt;-d, — destination&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor-client bundle — destination=dist/meteor-client.bundle.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Moreover, you don’t necessarily have to have the client and server on the same machine. The server can be hosted on a completely different computer, yet we can generate its appropriate client. This can be achieved by providing the &lt;code&gt;-c, — config&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor-client bundle — config=meteor-client.config.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here’s an example config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “runtime”: {
    “DDP_DEFAULT_CONNECTION_URL”: “http://127.0.0.1:8100”
  },
  “import”: [
    “meteor-base@1.0.4”,
    “mongo@1.1.14”,
    “reactive-var@1.0.11”,
    “jquery@1.11.10”,
    “tracker@1.1.1”,
    “standard-minifier-css@1.3.2”,
    “standard-minifier-js@1.2.1”,
    “es5-shim@4.6.15”,
    “ecmascript@0.6.1”,
    “shell-server@0.2.1”
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Each field in the configuration file represents the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;runtime&lt;/strong&gt; — Meteor’s runtime config. Most commonly used to set the URL of the Meteor server we would like to interface with.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;import&lt;/strong&gt; — A list of packages we would like to include in our bundle. The bundle will also take care of loading them in the right order and with the required dependencies&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also specify the server’s URL explicitly using the &lt;code&gt;— url&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ meteor-client bundle — url=http://127.0.0.1:8100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;How MCB works under the hood&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Basically, MCB takes a list of Meteor packages we would like to load in our client. Based on these, it builds a temporary Meteor application and composes a unified file from the fetched packages, with a focus in their chronological loading order.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Still sharing Client and Server code&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you’re using any sort of a configurable module bundler like Webpack, you can recreate one of Meteor’s greatest behaviors where we can load the same script on both client and server with a single definition. This will require you to add an alias for the server’s directory path, and define a special handler for imported Meteor packages. In the case of Webpack, the config extension should look like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  // …
  resolve: {
    alias: [
      api: “path/to/meteor/server”
    ]
  },
  externals: function (context, request, callback) {
    var match = request.match(/^meteor\/(.+)$/);
    var pack = match &amp;amp;&amp;amp; match[1];
    if (pack) {
      callback(null, ‘Package[“‘ + pack + ‘“]’);
    }
  }
  // …
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This should achieve the following result on the client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import { FooCollection, BarCollection } from “api/collections”;
Import { Accounts } from “meteor/accounts-base”;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And at the same time, we can use almost identical importations on the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import { FooCollection, BarCollection } from “./collections”;
Import { Accounts } from “meteor/accounts-base”;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;In conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;These were the key-concepts of Meteor Client Bundler. If you want to build an app while using the Meteor platform for all your stack, or you want to interact with a Meteor server and use any other front-end library or setup, MCB got everything you need, and will get you on the right track.&lt;/p&gt;

&lt;p&gt;For a simple example of using MBC, check out this &lt;a href="https://github.com/Urigo/React-Meteor-Todo-app"&gt;React-Meteor Todo app remake&lt;/a&gt; and for a more full-scale app check out the &lt;a href="https://github.com/Urigo/Ionic2CLI-Meteor-WhatsApp"&gt;Ionic CLI WhatsApp clone project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;More information regards MCB can be found in its official Github repository over here: &lt;a href="https://github.com/Urigo/meteor-client-bundler"&gt;https://github.com/Urigo/meteor-client-bundler&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I want to thank Eytan Manor for helping me make this library!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Build a WhatsApp Clone with Ionic 2, Angular 2, and Meteor!</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:41:12 +0000</pubDate>
      <link>https://dev.to/urigo/build-a-whatsapp-clone-with-ionic-2-angular-2-and-meteor-nig</link>
      <guid>https://dev.to/urigo/build-a-whatsapp-clone-with-ionic-2-angular-2-and-meteor-nig</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gfOXbrG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AePy_CSbglLEynzp104qiCw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gfOXbrG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AePy_CSbglLEynzp104qiCw.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A version of this post was originally published on the &lt;a href="http://blog.ionic.io/build-a-whatsapp-clone-with-ionic-2-angular-2-and-meteor/"&gt;Ionic Blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, a year has passed and a lot has happened: Angular 2.0 is now stable, including astonishing amount of new features for the platform. Ionic 2.0 entered RC stage and is very close to being final. Finally, Meteor &lt;a href="http://info.meteor.com/blog/announcing-meteor-1.4.2"&gt;reached version 1.4.2&lt;/a&gt;, with many improvements the community asked for (fast build times, full npm and yarn support, Node 4.6.1 and MongoDB 3 by default, etc..).&lt;/p&gt;

&lt;h2&gt;
  
  
  New Ionic/Meteor Whatsapp Tutorials
&lt;/h2&gt;

&lt;p&gt;Today, I’m happy to announce we are releasing two new versions of the Ionic/Meteor Whatsapp tutorial, this time with Angular 2.0 and Ionic 2.0, one using the &lt;strong&gt;Ionic CLI&lt;/strong&gt; and one using the &lt;strong&gt;Meteor CLI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In these tutorials, we’ll create a full WhatsApp clone using Angular 2 and Ionic 2. We’ll use Meteor’s realtime collections for the chat and Meteor’s simple Authentication packages for SMS-based authentication.&lt;/p&gt;

&lt;p&gt;It’s great to see the power of these two solutions working together, keeping the platforms up-to-date with the latest improvements in the Javascript ecosystem!&lt;/p&gt;

&lt;h2&gt;
  
  
  Angular2-Meteor
&lt;/h2&gt;

&lt;p&gt;By the way, if you noticed that the &lt;a href="https://angular-meteor.com/"&gt;Angular-Meteor.com&lt;/a&gt; website is much faster, it’s because we’ve completely re-written it using Angular 2 and universal rendering to generate it as a static website. On top of that, more features are coming to Angular2-Meteor very soon, including lazy loading of modules and support for the AOT compiler.&lt;/p&gt;

&lt;p&gt;If you’re thinking about migrating from Blaze to Angular2, or using them side by side, check out our &lt;a href="https://angular-meteor.com/tutorials/migration/angular2/introduction"&gt;migration tutorial here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Angular Meteor 1.2.0 Released</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:26:14 +0000</pubDate>
      <link>https://dev.to/urigo/angular-meteor-1-2-0-released-4c1</link>
      <guid>https://dev.to/urigo/angular-meteor-1-2-0-released-4c1</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EtbK3Tk9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AsDjbDGF8hKvcHoCSgGClBw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EtbK3Tk9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AsDjbDGF8hKvcHoCSgGClBw.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are happy to announce the release of the new angular 1.2.0 package, which takes advantage of the new build process introduced in Meteor 1.2 to make Angular developers feel even more comfortable and productive.&lt;/p&gt;

&lt;p&gt;The main difference between older versions is that now, we use Angular to process regular &lt;code&gt;HTML&lt;/code&gt; and &lt;code&gt;JS&lt;/code&gt; files instead of &lt;code&gt;.ng.html&lt;/code&gt; and &lt;code&gt;.ng.js.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We worked hard to make migrating an existing Angular app to Meteor easier. You can migrate by simply moving your entire existing project into Meteor, or also by using your own tools and connecting to a Meteor server, like &lt;a href="http://blog.ionic.io/ionic-and-meteor/"&gt;we demonstrated with Ionic&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For existing users, as the &lt;code&gt;HTML&lt;/code&gt; parsing is now happening by the &lt;code&gt;angular&lt;/code&gt; package, we should rename all &lt;code&gt;.ng.html&lt;/code&gt; files to &lt;code&gt;.html&lt;/code&gt; and remove the &lt;code&gt;blaze-html-templates&lt;/code&gt; package to reduce load time on the client.&lt;/p&gt;

&lt;p&gt;Also, the new &lt;code&gt;angular&lt;/code&gt; package processes &lt;code&gt;JS&lt;/code&gt; files with Babel for &lt;code&gt;Ecmascript 2015&lt;/code&gt; support and &lt;code&gt;ng-annotate&lt;/code&gt; out of the box.&lt;/p&gt;

&lt;p&gt;It also adds the &lt;code&gt;decorators&lt;/code&gt; syntax from Babel so it will be easier to use the &lt;a href="https://github.com/pbastowski/angular2-now/"&gt;&lt;code&gt;pbastowski:angular2-now&lt;/code&gt;&lt;/a&gt; package. This lets you write Angular 2.0 syntax in your Angular 1.x application, which we recommend as a best practice.&lt;/p&gt;

&lt;p&gt;That means we should rename all &lt;code&gt;.ng.js&lt;/code&gt; files to &lt;code&gt;.js&lt;/code&gt; and remove the default &lt;code&gt;ecmascript&lt;/code&gt; Meteor core package from our projects.&lt;/p&gt;

&lt;p&gt;The new package also uses the Meteor 1.2 caching compilers to make the build process faster.&lt;/p&gt;

&lt;p&gt;If you are using the &lt;code&gt;accounts-ui&lt;/code&gt; package, we now have &lt;a href="https://github.com/dotansimha/accounts-ui-angular"&gt;&lt;code&gt;dotansimha:accounts-ui-angular&lt;/code&gt;&lt;/a&gt; package instead.&lt;/p&gt;

&lt;p&gt;If you still want to continue using the old build process and combine Blaze and Angular templates, you can use the &lt;code&gt;angular-with-blaze&lt;/code&gt; package instead of the &lt;code&gt;angular\&lt;/code&gt; package and keep using the same &lt;code&gt;ng.html&lt;/code&gt; and &lt;code&gt;ng.js&lt;/code&gt; file extensions and the &lt;a href="https://github.com/Urigo/angular-blaze-template"&gt;&lt;code&gt;urigo:angular-blaze-template&lt;/code&gt;&lt;/a&gt; package to include Blaze templates inside your Angular templates.&lt;/p&gt;

&lt;p&gt;Going forward to version 1.3, we will start changing our API to be directed into the best practices we’ve recommended:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Making the data API as similar as possible to the current and the future native Meteor API&lt;/li&gt;
&lt;li&gt;  Removing the &lt;code&gt;autobind&lt;/code&gt; feature to get better performance out of the box&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get ready, you can start using your &lt;code&gt;$meteor&lt;/code&gt; &lt;a href="http://angular-meteor.com/api/meteorCollection"&gt;services&lt;/a&gt; without &lt;code&gt;autobind&lt;/code&gt; (sending &lt;code&gt;false&lt;/code&gt; to that parameter).&lt;/p&gt;

&lt;p&gt;Thanks for all the help we got from the community on this release!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/idanwe"&gt;Idan Wender&lt;/a&gt;, &lt;a href="https://github.com/cantoine"&gt;Chris Antoine&lt;/a&gt;, &lt;a href="https://github.com/DAB0mB"&gt;Eytan Manor&lt;/a&gt;, &lt;a href="https://github.com/canac"&gt;Caleb Cox&lt;/a&gt;, &lt;a href="https://github.com/barbatus"&gt;barbatus&lt;/a&gt;, &lt;a href="https://github.com/Urigo"&gt;Uri Goldshtein&lt;/a&gt;, &lt;a href="https://github.com/kimberger"&gt;Joseph Kimberger&lt;/a&gt;, &lt;a href="https://github.com/birkskyum"&gt;Birk Skyum&lt;/a&gt;, &lt;a href="https://github.com/Tallyb"&gt;Tally Barak&lt;/a&gt;, &lt;a href="https://github.com/dotansimha"&gt;Dotan Simha&lt;/a&gt;, &lt;a href="https://github.com/netanelgilad"&gt;Netanel Gilad&lt;/a&gt;, &lt;a href="https://github.com/dinesh36"&gt;dinesh36&lt;/a&gt;, &lt;a href="https://github.com/DumpOfTheVar"&gt;DumpOfTheVar&lt;/a&gt;, &lt;a href="https://github.com/Vercryger"&gt;Karim Abuzaid&lt;/a&gt;, &lt;a href="https://github.com/marvinmarnold"&gt;marvinmarnold&lt;/a&gt;, &lt;a href="https://github.com/dajocarter"&gt;David Carter&lt;/a&gt;, &lt;a href="https://github.com/EyalRonel"&gt;Eyal Ronel&lt;/a&gt;, &lt;a href="https://github.com/MarkPhillips7"&gt;MarkPhillips7&lt;/a&gt;, &lt;a href="https://github.com/nickbenes"&gt;Nick Benes&lt;/a&gt;, &lt;a href="https://github.com/ShMcK"&gt;Shawn Mckay&lt;/a&gt;, &lt;a href="https://github.com/Erdou"&gt;Erdou&lt;/a&gt;, &lt;a href="https://github.com/ssuksawat"&gt;Sompop Suksawat&lt;/a&gt;, &lt;a href="https://github.com/MilosStanic"&gt;Miloš Stanić&lt;/a&gt;, &lt;a href="https://github.com/mbeaudru"&gt;BEAUDRU Manuel&lt;/a&gt;, &lt;a href="https://github.com/BrainCrumbz"&gt;BrainCrumbz&lt;/a&gt;, &lt;a href="https://github.com/davidyaha"&gt;David Yahalomi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please let me know what you think in the comments below.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>GraphQL as a best practice for modern Angular apps?</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:26:14 +0000</pubDate>
      <link>https://dev.to/urigo/graphql-as-a-best-practice-for-modern-angular-apps-24fn</link>
      <guid>https://dev.to/urigo/graphql-as-a-best-practice-for-modern-angular-apps-24fn</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Angular, meet GraphQL&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this post, I’ll make the case for why Angular needs a best practice for communicating with the server, and why GraphQL should be that best practice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NjdrHv8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AyTMBzO8zfEhKr4Lky6pjZQ.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NjdrHv8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AyTMBzO8zfEhKr4Lky6pjZQ.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices
&lt;/h2&gt;

&lt;p&gt;The Angular community is establishing best practices so that we all can benefit from making our apps more performant, easier to maintain, and more modern.&lt;/p&gt;

&lt;p&gt;Some of the current best practices include composing everything into &lt;a href="https://docs.angularjs.org/guide/component"&gt;Components&lt;/a&gt;, using one-way data binding, lazy loading, having an immutable global state management (Redux &amp;amp; ng-rx), and more…&lt;/p&gt;

&lt;p&gt;That is all great, and means that if we will follow those best practices our apps will behave better and will look more modern…&lt;/p&gt;

&lt;p&gt;…until we get to data fetching from the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data fetching
&lt;/h2&gt;

&lt;p&gt;Today, whether we are developing in a large company, consulting, or writing our own app, when we fetch data from the server we are often left with old practices that don’t address the needs of a modern app.&lt;/p&gt;

&lt;p&gt;Also, we are kind of powerless and unable to decide how the data will be supplied to our apps by the server, even though the way we fetch the data to our app is at least as meaningful to the way our app behaves as how we present it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We should come up with best practices for data fetching that is more in line with the modern way we write our apps. These should take into consideration the following needs: data documentation, network latency, server side rendering and faster initial loading, real time communication patterns, latency compensation, and optimistic UI.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  REST
&lt;/h2&gt;

&lt;p&gt;REST is the current protocol we go around when we talking about app data fetching. REST has its benefits, but it was evolved in a time where the web was very different from today, when everything was about static HTML and forms and not about apps.&lt;/p&gt;

&lt;p&gt;Here are the areas where REST is currently lacking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;self documentation&lt;/strong&gt; — when you send a request to a REST endpoint, there is nothing in the protocol that tells you what you are going to get (and not everyone has the resources to create a nice, updated documentation like Twitter)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;REST doesn’t support &lt;strong&gt;real time data&lt;/strong&gt; fetching&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tough choices when designing your REST endpoint, which I’ll elaborate on below&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Over-fetching&lt;/strong&gt; — When one endpoint serves all the data, each Component calls it again and again. This means it serves more fields than the component needed &lt;em&gt;and&lt;/em&gt; we call it many times, creating more load on the server&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Under-fetching&lt;/strong&gt; — When many endpoints serve multiple resources and fields. This creates many round trips for one Component as well as complex joins on the client.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kh6Wnkgt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2Ad7JZJH23iJZONJV536q2iQ.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kh6Wnkgt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2Ad7JZJH23iJZONJV536q2iQ.png%3Fraw%3Dtrue" alt="" title="The Discourse REST API — look on the links at the bottom on the GraphQL version of this"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rethinking data fetching
&lt;/h2&gt;

&lt;p&gt;So it looks like we need to rethink data fetching, just like we rethought web apps.&lt;/p&gt;

&lt;p&gt;Luckily, Facebook ran into the same problem in 2012 when they needed to rethink the way they fetch data as they wrote their mobile apps on top of their existing stack.&lt;/p&gt;

&lt;p&gt;They developed a solution, and open sourced it as &lt;a href="http://graphql.org/"&gt;GraphQL&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  GraphQL
&lt;/h2&gt;

&lt;p&gt;GraphQL is the new data communication protocol for modern apps.&lt;/p&gt;

&lt;p&gt;The server communicates what data it can provide and the client specifies what data it needs in a &lt;strong&gt;simple, graph-like structure&lt;/strong&gt;, in &lt;strong&gt;one round trip&lt;/strong&gt;, no matter how deep, how complex, or how many resources the data contains.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--boxI-M3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AvPIBVnQZAlRws-aXo6kksQ.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--boxI-M3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AvPIBVnQZAlRws-aXo6kksQ.gif%3Fraw%3Dtrue" alt="" title="GraphQL has built in documentation so any server can use the GraphiQL editor without the need of setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means: one request to get exactly the information the app needs, when it needs it. &lt;strong&gt;No over-fetching and under-fetching.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With that, each component needs to specify its data dependencies and a client library will merge them into one request. There’s no need for a shared service with prepared fetching functions.&lt;/p&gt;

&lt;p&gt;GraphQL is also not a storage engine! You can connect it to an existing REST endpoint or SQL and NoSql databases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared best practices between frameworks
&lt;/h2&gt;

&lt;p&gt;For all the reasons above, GraphQL is already the best practice for fetching data with React. Also, all the Facebook apps and clients use GraphQL.&lt;/p&gt;

&lt;p&gt;If the Angular community embraces GraphQL as a best practice, it would open the door to sharing more tools and knowledge with the React community.&lt;/p&gt;




&lt;p&gt;To start learning about GraphQL, take a look at these sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/apollo-stack/why-graphql-is-the-future-3bec28193807#.3wpy7r34b"&gt;Why GraphQL is the future&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/apollo-stack/the-basics-of-graphql-in-5-links-9e1dc4cac055#.uvh5c43kt"&gt;The basics of GraphQL in 5 minutes&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/apollo-stack/discourse-in-graphql-part-1-ee1ffd8a22df#.ehvb5vgl1"&gt;Replacing Discourse REST API with GraphQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://docs.apollostack.com/apollo-client/angular2.html"&gt;Angular-Apollo Docs&lt;/a&gt; and &lt;a href="https://github.com/apollostack/angular2-apollo"&gt;Github Repo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.graphql.com/articles/angular-graphql-faster-modern-apps"&gt;Building faster modern apps with Angular and GraphQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=qpGnPbpkcZM"&gt;https://www.youtube.com/watch?v=qpGnPbpkcZM&lt;/a&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Join the fastest-growing GraphQL community on &lt;a href="http://www.apollostack.com/#slack"&gt;Apollo Slack&lt;/a&gt; or &lt;a href="https://medium.com/apollo-stack"&gt;subscribe to this publication&lt;/a&gt; for more articles like this and get involved!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Data management and AJAX server fetching for Angular Component based apps</title>
      <dc:creator>Uri Goldshtein</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:26:13 +0000</pubDate>
      <link>https://dev.to/urigo/data-management-and-ajax-server-fetching-for-angular-component-based-apps-4m7</link>
      <guid>https://dev.to/urigo/data-management-and-ajax-server-fetching-for-angular-component-based-apps-4m7</guid>
      <description>&lt;p&gt;One of the most powerful concepts introduced by Angular 2 is the move to a Component based architecture.&lt;/p&gt;

&lt;p&gt;Components are pieces of UI and logic bound together into &lt;strong&gt;reusable&lt;/strong&gt; and &lt;strong&gt;self contained&lt;/strong&gt; units.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ryh1_VaZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A-xibJG0BNHwXZxEvOwadIQ.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ryh1_VaZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2A-xibJG0BNHwXZxEvOwadIQ.png%3Fraw%3Dtrue" alt="" title="Components in Angular 2 and data flow between them"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two important benefits about Components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We can &lt;strong&gt;reuse&lt;/strong&gt; Components throughout our apps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When something changes in the inner logic and UI of a Component, it &lt;strong&gt;shouldn’t affect&lt;/strong&gt; the other Components outside of it&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those are great benefits, but are they still valid when we start interacting with the server?&lt;/p&gt;

&lt;p&gt;I’ll argue in this article that the current way of calling the server with REST API through central Angular services is not a good fit and that co-locating queries with view logic is the natural extension to the component based architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calling the server with REST API through central services
&lt;/h2&gt;

&lt;p&gt;Currently in Angular apps, in order to fetch data from the server, we usually import a service that handle the fetching logic for us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var app = angular.module('myApp', ['ngResource']);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.factory("Friend", function($resource) {
  return $resource("/api/friend/:id");
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.controller("FriendListItemCtrl", function($scope, Friend) {
  Friend.get({ id: 1 }, function(data) {
    $scope.friend = data;
  });
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When we moved to Component based architecture, we switched the Controller to the Component class, but in most examples out there, the way we fetch data hasn’t really changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Friend } from ‘./friend’;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Injectable()
export class FriendService {
  constructor(private http: Http) { }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  getFriend(id: string): Promise&amp;lt;Friend[]&amp;gt; {
    return this.http.get(`/api/friend/${id}`)
                    .toPromise()
                    .then(res =&amp;gt; res.json().data as Friend[]);
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;........................
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from ‘@angular/core’;
import { FriendService } from ‘./friend.service’;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: ‘friend’,
  templateUrl: ......
})
export class FriendComponent implements OnInit {
  friend: Friend;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  constructor(private friendService: FriendService){
    this.friendService.getFriend(id)
                      .then(friend =&amp;gt; this.friend = friend);
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that introduces an issue — What happens if now we need to get different data from the server?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s look at an example of the issue,&lt;/strong&gt; we’ll use this Component tree as an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MEbMaWuZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AFBqKwp2v4wvhFEGYtUGDgg.jpeg%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MEbMaWuZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AFBqKwp2v4wvhFEGYtUGDgg.jpeg%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and let’s say the we call a service on the parent &lt;code&gt;FriendsList\&lt;/code&gt; Component that fetches all the data for the Component tree.&lt;/p&gt;

&lt;p&gt;Now let’s ask two simple questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What happens when we need to change Component to display new fields?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How do we reuse Component in a different place in our app and still fetch the data it needs?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;For the first question&lt;/strong&gt;, we will need to change the server endpoint to either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Change the existing one to fetch the new data (might change other Components who use the same endpoint and service)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Add a new endpoint with the new data structure we want and change the service to support the new endpoint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In either of those solutions — Our Components are no longer &lt;strong&gt;self contained&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As for the second question&lt;/strong&gt;, we would need to create or change the service to support the new Component tree that in under, making it &lt;strong&gt;not reusable!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_rDVkUAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AzOY5GybNa8FxdBiLQCa9pw.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_rDVkUAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2AzOY5GybNa8FxdBiLQCa9pw.png%3Fraw%3Dtrue" alt="" title="A diagram I stole from a talk (referenced at the end) that shows that if child component’s AJAX requirements has changed, it will change the whole tree and the server as well"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Needed solution
&lt;/h2&gt;

&lt;p&gt;So what do we need that is missing with current solutions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Each Component could &lt;strong&gt;specify its own data dependencies&lt;/strong&gt; without knowing a central service or another parent Component in the current render tree&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we render a tree of Components, we will &lt;strong&gt;fetch exactly&lt;/strong&gt; the information that this Component tree needs which is a &lt;strong&gt;combination of the requirements of each Component&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We would do that in &lt;strong&gt;one single request&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need an &lt;strong&gt;API layer&lt;/strong&gt; that will bring us &lt;strong&gt;new fields without changing&lt;/strong&gt; existing and exposing new endpoint&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Solution — GraphQL Client
&lt;/h2&gt;

&lt;p&gt;With GraphQL, we can &lt;strong&gt;co-locate the server data requirements&lt;/strong&gt; for each Component, and then use a GraphQL Client like &lt;a href="https://github.com/apollostack/angular2-apollo"&gt;angular2-apollo&lt;/a&gt; to handle the merging of those needs into one single request that gets exactly what we need.&lt;/p&gt;

&lt;p&gt;Let’s have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';
import { Angular2Apollo } from 'angular2-apollo';
import gql from 'graphql-tag';

const FriendsQuery = gql`
  query getFriends {
    friends {
      id
    }
  }
`;

@Component({
  selector: 'friends-list',
  template: `
    &amp;lt;div *ngFor="let friend of friends"&amp;gt;
      &amp;lt;friends-list-item [friendId]="friend.id"&amp;gt;&amp;lt;/friends-list-item&amp;gt;
    &amp;lt;/div&amp;gt;
  `
})
export class FriendsListComponent {
  friends: FriendId[];

  constructor(private apollo: Angular2Apollo) {
    this.friends = this.apollo.watchQuery({
      query: FriendsQuery
    });
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, Input } from '@angular/core';
import { Angular2Apollo } from 'angular2-apollo';
import gql from 'graphql-tag';

const FriendItemQuery = gql`
  query getFriendItem($id: Int!) {
    Friend(id: $id) {
      id
      is_viewer_friend
      profilePicture {
        url      
      }
    }
  }
`;

@Component({
  selector: 'friends-list-item',
  template: `
    &amp;lt;div&amp;gt;
      &amp;lt;img src="friend.profilePicture.url"/&amp;gt;
      &amp;lt;friend-info [friendId]="friend.id"&amp;gt;&amp;lt;/friend-info&amp;gt;
      {{friend.is_viewer_friend}}       
    &amp;lt;/div&amp;gt;
  `
})
export class FriendListItemComponent {
  @Input() friendId: number;
  friend: FriendListItem;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;constructor(private  apollo: Angular2Apollo) {
    this.friend = this.apollo.watchQuery({
      query: FriendItemQuery,
      variables: {id: this.friendId}
    });
  }  
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, Input } from '@angular/core';
import { Angular2Apollo } from 'angular2-apollo';
import gql from 'graphql-tag';

const FriendInfoQuery = gql`
  query getFriendInfo($id: Int!) {
    Friend(id: $id) {
      id
      name
      mutual_friends {
        count      
      }
    }
  }
`;

@Component({
  selector: 'friends-info',
  template: `
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;{{friend.name}}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;{{friend.mutual_friends.count}} mutual friends&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  `
})
export class FriendInfoComponent {
  @Input() friendId: number;
  friend: FriendInfo;

  constructor(private  apollo: Angular2Apollo) {
    this.friend = this.apollo.watchQuery({
      query: FriendInfoQuery,
      variables: {id: this.friendId}
    });
  }  
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;this is of course not a full working app, I’ll add links to full implementation at the end&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now let’s get back to our original questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What happens when we need to change Component to display new fields?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How do we reuse Component in a different place in our app and still fetch the data it needs?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The answer now, is that you only need to change &amp;lt;FriendInfo&amp;gt; Component itself and that’s it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const FriendInfoQuery = gql`
  query getFriendInfo($id: Int!) {
    Friend(id: $id) {
      id
      name
      mutual_friends {
        count      
      }
      age
    }
  }
`;
...
  template: `
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;{{friend.name}}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;{{friend.mutual_friends.count}} mutual friends&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;{{friend.age}} years old&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  `
})
export class FriendInfoComponent {
...  
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s it!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  We don’t need to change any of its parent Components&lt;/li&gt;
&lt;li&gt;  We don’t need to change the API endpoint&lt;/li&gt;
&lt;li&gt;  We can move it around and reuse it in any Component tree&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is now a true &lt;strong&gt;reusable, self contained&lt;/strong&gt; Component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this article I’ve tried to make the point that we should adjust our way of fetching data from the server to the new paradigms Angular 2.0 introduced.&lt;/p&gt;

&lt;p&gt;It’s Important to note that those concepts and solutions are also true and valid in an &lt;strong&gt;Angular 1.x&lt;/strong&gt; app that is Component based (and Apollo Client work with it as well).&lt;/p&gt;

&lt;p&gt;Also, an important point is that you can use this solution alongside your regular REST services and not instead of them, add it where it fits and make sense to you.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are many more benefits for this type of architecture and more details about how we manage those queries and app state which I’ll touch on &lt;a href="https://medium.com/apollo-stack/"&gt;later posts&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here are few notable talks and resources about those techniques, some are for React but the concepts are still the same:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=9sc8Pyc51uU"&gt;Data fetching for React applications at Facebook&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=qpGnPbpkcZM&amp;amp;index=3&amp;amp;list=PLhCf3AUOg4PgQoY_A6xWDQ70yaNtPYtZd"&gt;Modernize your Angular apps with GraphQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/apollostack/GitHunt-angular2"&gt;Angular2-Githunt example&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;To learn more about how Angular works with GraphQL, hear directly from Angular core team member Jeff Cross at the upcoming &lt;a href="http://graphqlsummit.com"&gt;GraphQL Summit&lt;/a&gt; in San Francisco on October 26th!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G21cOmq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ALJ-QIT-8DRycuYjPnQnkvA.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G21cOmq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/the-guild-org/oneblog/blob/master/img/704/1%2ALJ-QIT-8DRycuYjPnQnkvA.png%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
