<?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: Derian Sibaja</title>
    <description>The latest articles on DEV Community by Derian Sibaja (@dersibcha).</description>
    <link>https://dev.to/dersibcha</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%2F885354%2F3bb08763-3cd5-4f9a-bb01-6d35ed86fb30.jpeg</url>
      <title>DEV Community: Derian Sibaja</title>
      <link>https://dev.to/dersibcha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dersibcha"/>
    <language>en</language>
    <item>
      <title>Graphql test</title>
      <dc:creator>Derian Sibaja</dc:creator>
      <pubDate>Fri, 01 Jul 2022 20:42:01 +0000</pubDate>
      <link>https://dev.to/dersibcha/graphql-test-282f</link>
      <guid>https://dev.to/dersibcha/graphql-test-282f</guid>
      <description>&lt;h1&gt;
  
  
  Graphql API Code Cookbook
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Most of the APIs request an endpoint to access a predefined data structure. If you want to access other resources, it is necessary to request another endpoint, it makes the procces kind of tricky.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We only define a single endpoint (for example &lt;a href="http://example/graphql"&gt;http://example/graphql&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Since this is a query language, all actions are done through a POST.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;GraphQL allow us to retrieve only the data we need by using a query language for web APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recipe
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CRUD GraphQL API with Nodejs, Express &amp;amp; MongoDB
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create a new directory to store the project, run npm init to configure the new project&lt;/li&gt;
&lt;li&gt;Run npm install to create our package.json file&lt;/li&gt;
&lt;li&gt;Create a server.js file (entry point for our server)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the src folder and the below required folders and files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create src/schema directory and an index.js file (will contain the business logic)&lt;/li&gt;
&lt;li&gt;Create a src/resolvers directory and an index.js file.&lt;/li&gt;
&lt;li&gt;Create an src/models directory and a post.js which holds what a post should look like.
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── src
│   ├── schema
│   │   └── index.js
│   ├── resolvers
│   │   └── index.js
│   └── models
│       └── post.js
├── package-lock.json
├── package.json
└── server.js
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Install the dependencies&lt;/p&gt;

&lt;h4&gt;
  
  
  Using npm
&lt;/h4&gt;



&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # npm
  $ npm install --save express express-graphql graphql body-parser
&lt;/code&gt;&lt;/pre&gt;



&lt;h4&gt;
  
  
  Using yarn
&lt;/h4&gt;



&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # yarn
  $ yarn add --save express express-graphql graphql body-parser
&lt;/code&gt;&lt;/pre&gt;



&lt;blockquote&gt;
&lt;p&gt;You can also install "nodemon" locally to avoid having to restart your server with each change&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $npm install --save-dev nodemon
&lt;/code&gt;&lt;/pre&gt;



&lt;blockquote&gt;
&lt;p&gt;Also you need to update your "package.json"  for using "nodemon".&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&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="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon server.js"&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;/li&gt;
&lt;/ol&gt;

</description>
      <category>graphql</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Test post</title>
      <dc:creator>Derian Sibaja</dc:creator>
      <pubDate>Fri, 01 Jul 2022 02:33:31 +0000</pubDate>
      <link>https://dev.to/dersibcha/test-post-4mdo</link>
      <guid>https://dev.to/dersibcha/test-post-4mdo</guid>
      <description>&lt;p&gt;This is a test post&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OfahXQ4O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbxj16dgopv0m9amihyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OfahXQ4O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbxj16dgopv0m9amihyz.png" alt="Image description" width="100" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
  </channel>
</rss>
