<?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: Humberto Arroyo</title>
    <description>The latest articles on DEV Community by Humberto Arroyo (@humbertoa6).</description>
    <link>https://dev.to/humbertoa6</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%2F692821%2Ff6201b1e-0312-481c-b865-cfdfac5b3435.jpeg</url>
      <title>DEV Community: Humberto Arroyo</title>
      <link>https://dev.to/humbertoa6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/humbertoa6"/>
    <language>en</language>
    <item>
      <title>How to Create a GraphQL API With Ruby on Rails: A Step-by-Step Guide - Part 1</title>
      <dc:creator>Humberto Arroyo</dc:creator>
      <pubDate>Tue, 16 Jan 2024 22:59:25 +0000</pubDate>
      <link>https://dev.to/humbertoa6/developing-with-graphql-in-ruby-on-rails-a-step-by-step-guide-part-1-4gdi</link>
      <guid>https://dev.to/humbertoa6/developing-with-graphql-in-ruby-on-rails-a-step-by-step-guide-part-1-4gdi</guid>
      <description>&lt;p&gt;In the ever-evolving world of Ruby on Rails web development, the adoption of GraphQL has taken a leading role due to its flexibility and efficiency in creating APIs. In this article, I'll walk you through a step-by-step approach to integrating GraphQL into a Rails project focused on &lt;strong&gt;articles&lt;/strong&gt; and &lt;strong&gt;comments&lt;/strong&gt;. From initial setup to creating specific queries and resolvers, we'll explore together how to leverage the power of GraphQL in our application.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating the Rails Application and Configuring GraphQL
&lt;/h4&gt;

&lt;p&gt;Before we dive into the fascinating world of GraphQL, make sure you have your development environment up and running.&lt;/p&gt;

&lt;p&gt;Let's start by creating a new Rails application and configuring GraphQL. Let's run the following commands to start our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new articles-graphql-app
cd articles-graphql-app
bundle add graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This set of commands sets the basics for integrating GraphQL into our application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rails new articles-graphql-app&lt;/code&gt;: This command creates a new Rails application named "articles-graphql-app".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd articles-graphql-app&lt;/code&gt;: This command changes the current working directory to the newly created "articles-graphql-app" directory. Move inside the project folder to perform specific actions in that context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;bundle add graphql&lt;/code&gt;: Adds the graphql gem to your project's Gemfile. The graphql gem provides the necessary tools to implement GraphQL in your Rails application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's run the &lt;code&gt;rails generate graphql:install&lt;/code&gt; command in the root of the project which sets up the basic infrastructure for GraphQL in your Rails application. It organizes your GraphQL code into specific folders, making it easier to manage and scale as you add more functionality to your GraphQL API, generating the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Route for GraphQL that adds a new route in your &lt;code&gt;config/routes.rb&lt;/code&gt; file that maps the &lt;code&gt;/graphql&lt;/code&gt; URL to the generated GraphQL driver. This route acts as the entry point for GraphQL requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Controller named &lt;code&gt;GraphqlController&lt;/code&gt; in the &lt;code&gt;app/controllers&lt;/code&gt; directory. This controller is responsible for handling GraphQL requests and orchestrating the execution of queries and mutations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Folder &lt;code&gt;app/graphql&lt;/code&gt; in which all related GraphQL files will be organized. Within &lt;code&gt;app/graphql&lt;/code&gt;, specific subfolders are created to organize different components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mutations&lt;/strong&gt;: Here you can define and manage GraphQL mutations that modify data in your application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;resolvers&lt;/strong&gt;: In this folder, you can implement resolvers that handle GraphQL queries and mutations. The resolvers are responsible for obtaining and returning the requested data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;types&lt;/strong&gt;: Contains the definitions of GraphQL types that represent your models and data structures in the application.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h4&gt;
  
  
  Generating models and data for Post and Comment models
&lt;/h4&gt;

&lt;p&gt;To be able to interact with the models you must generate the models and data. In this case you are going to use a gem called &lt;code&gt;faker&lt;/code&gt;. We will run the following command to add the gem to the Gemfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle add faker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Faker&lt;/strong&gt; is a useful tool to generate dummy data in a realistic way, which will ease the creation of test data for your article and comment models.&lt;/p&gt;

&lt;p&gt;Now you are going to generate the model for &lt;strong&gt;Post&lt;/strong&gt; that includes two fields: &lt;strong&gt;title&lt;/strong&gt; of type string and &lt;strong&gt;content&lt;/strong&gt; of type text. This model will represent the articles in the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate model Post title:string content:text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are going to generate the &lt;strong&gt;Comment&lt;/strong&gt; model that includes a text content field and establishes a &lt;strong&gt;belongs_to&lt;/strong&gt; association with the &lt;strong&gt;Post&lt;/strong&gt; model. This will allow each comment to be linked to a specific article in our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate model Comment post:belongs_to content:text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must set the reverse relationship in the Post model. Open the &lt;code&gt;app/models/post.rb&lt;/code&gt; file and add the line &lt;code&gt;has_many :comments&lt;/code&gt; to indicate that an article can have many comments. Your &lt;code&gt;app/models/post.rb&lt;/code&gt; file might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:comments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's edit the &lt;code&gt;db/seeds.rb&lt;/code&gt; file so that you can create 20 articles, each with a generated fake title and three related comments, each with fictitious content. The script should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'faker'&lt;/span&gt;


&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;times&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="ss"&gt;title: &lt;/span&gt;&lt;span class="no"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Lorem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sentence&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;times&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="no"&gt;Comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="ss"&gt;post: &lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;content: &lt;/span&gt;&lt;span class="no"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Lorem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;paragraph&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'Seed data created successfully!'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run the seed script, simply place this code in the &lt;code&gt;db/seeds.rb&lt;/code&gt; file. Then, you can run the following commands to ensure that all the data has been created as expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:migrate
rails db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ready to move on to the next steps?  🚀&lt;/p&gt;

&lt;h4&gt;
  
  
  Setting Resolvers for Posts
&lt;/h4&gt;

&lt;p&gt;Basically a resolver is a function that handles the logic to obtain the data requested by a GraphQL query or mutation. In other words, a resolver answers the question "how to get this specific data?".&lt;/p&gt;

&lt;p&gt;Now let's set up resolvers and GraphQL types to handle specific queries. Add this line to &lt;code&gt;app/graphql/types/query_type.rb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;resolver: &lt;/span&gt;&lt;span class="no"&gt;Resolvers&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostsResolver&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To display the file &lt;code&gt;app/graphql/types/query_type.rb&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Types&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;QueryType&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;BaseObject&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="s2"&gt;"The query root of this schema"&lt;/span&gt;

    &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;resolver: &lt;/span&gt;&lt;span class="no"&gt;Resolvers&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostsResolver&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding the &lt;code&gt;:posts&lt;/code&gt; field to your GraphQL query type (&lt;code&gt;QueryType&lt;/code&gt;) and associating it with the &lt;code&gt;Resolvers::PostsResolver&lt;/code&gt;, you are configuring GraphQL to handle posts queries. This resolver will take care of getting and returning the necessary information when a posts query is performed.&lt;/p&gt;

&lt;p&gt;Now we're going to create the resolver to get all the posts in &lt;code&gt;app/graphql/resolvers/posts_resolver.rb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Resolvers&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostsResolver&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;BaseResolver&lt;/span&gt;
    &lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostType&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;
      &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting Types for Posts and Comments
&lt;/h4&gt;

&lt;p&gt;To give some context, a Type refers to the data structure that you can query or modify using the GraphQL query language. In GraphQL, types represent the entities in our system and define the fields that can be queried or mutated on those entities.&lt;/p&gt;

&lt;p&gt;Now let's define the post type in &lt;code&gt;app/graphql/types/post_type.rb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Types::PostType&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;BaseObject&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:comments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CommentType&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;description: &lt;/span&gt;&lt;span class="s2"&gt;"This post's comments, or null if this post has comments disabled."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By creating the PostType type in &lt;code&gt;app/graphql/types/post_type.rb&lt;/code&gt;, you are defining how it will be structured and what fields will be available when information about a post is requested through GraphQL. This PostType type includes fields such as id, title, and content, and also provides a comments field that represents the comments associated with that post.&lt;/p&gt;

&lt;p&gt;With the post type definition in place, your GraphQL schema now has a clear representation of how posts are structured and their relationships to other types.&lt;/p&gt;

&lt;p&gt;Now let's define the comment type in &lt;code&gt;app/graphql/types/comment_type.rb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Types::CommentType&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;BaseObject&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Types&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PostType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
  &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="ss"&gt;:content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;null: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this CommentType type, you are specifying that a comment has fields such as id, post, and content. The post field represents the relationship between a comment and the post it belongs to, using the PostType type you defined earlier.&lt;/p&gt;

&lt;p&gt;With the comment type definition in place, you now have a more complete GraphQL schema that clearly represents the structure of your data&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing the Posts API
&lt;/h4&gt;

&lt;p&gt;After setting up our GraphQL API for Posts, execute your &lt;code&gt;rails server&lt;/code&gt; and now you can test it using cURL directly from the command line or with more visual tools like Postman:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --location 'http://localhost:3001/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"query {\n  posts {\n    id\n    title\n    comments {\n        id\n        content\n    }\n  }\n}\n","variables":{}}'

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

&lt;/div&gt;



&lt;p&gt;In Postman, for example, the result should look like this:&lt;/p&gt;

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

&lt;p&gt;In this journey through implementing GraphQL in a Ruby on Rails application, we've covered everything from initial setup to creating GraphQL resolvers and types to handle specific queries. GraphQL gives us the flexibility to request exactly the data we need, resulting in more efficient and tailored APIs.&lt;/p&gt;

&lt;p&gt;We've explored creating types, resolvers and how to test our queries using cURL and Postman. Now with a solid foundation, but in the &lt;strong&gt;next&lt;/strong&gt; post we will add to our schema GraphQL includes an additional query called post, which uses the Resolvers::PostResolver resolver to handle retrieving a specific post by its id.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>graphql</category>
      <category>tutorial</category>
      <category>ruby</category>
    </item>
    <item>
      <title>PGP - Encrypt/Decrypt file with Ruby on Rails (Part 3)</title>
      <dc:creator>Humberto Arroyo</dc:creator>
      <pubDate>Thu, 29 Sep 2022 14:23:01 +0000</pubDate>
      <link>https://dev.to/humbertoa6/pgp-encryptdecrypt-file-with-ruby-on-rails-part-3-3log</link>
      <guid>https://dev.to/humbertoa6/pgp-encryptdecrypt-file-with-ruby-on-rails-part-3-3log</guid>
      <description>&lt;p&gt;In the previous two posts we have seen:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/humbertoa6/pgp-encryptdecrypt-file-with-ruby-on-rails-part-3-3log"&gt;Introduction Encryption and Decryption&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/humbertoa6/pgp-create-a-publicprivate-key-pairpart-2-4a7b"&gt;Create a Public/Private Key Pair&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this tutorial we are going to explain how to encrypt and decrypt in Ruby on Rails with the &lt;a href="https://rubygems.org/gems/gpgme"&gt;GPGME gem&lt;/a&gt;.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;GPGME provides an encryption, decryption, signing, signature verification and key management&lt;/li&gt;
&lt;li&gt;Encrypt data with GPGME gem&lt;/li&gt;
&lt;li&gt;Decrypt data with GPGME gem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ruby gem GPGME (GnuPG Made Easy) is a library designed to make access to GnuPG easier for applications. &lt;strong&gt;GPGME provides&lt;/strong&gt; a High-Level Crypto API for encryption, &lt;strong&gt;decryption, signing, signature verification and key management&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encrypt data with GPGME gem
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Must be have an imported recipient's public key.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;crypto&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'recipient_public_key.pgp'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Read file or data to encrypt
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;plaintext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'file.csv'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;#Our file contains following data:&lt;/span&gt;
&lt;span class="c1"&gt;#last_name, name, mobile_phone\nSmith,Chris,3336985726&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Encrypt data with following options

&lt;ul&gt;
&lt;li&gt;Recipients: For which recipient do you want to encrypt this file.&lt;/li&gt;
&lt;li&gt;Sign: Must be true, performs a combined sign and encrypt operation.&lt;/li&gt;
&lt;li&gt;Signers: Sender of encrypt file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;sign: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;signers: &lt;/span&gt;&lt;span class="s1"&gt;'sender@foo.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;recipients: &lt;/span&gt;&lt;span class="s1"&gt;'recipient@foo.com'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encrypt&lt;/span&gt; &lt;span class="n"&gt;plaintext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create and save encrypted file in gpg extension:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'encrypted_file.gpg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wb'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;bytes_written&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have a file with this name &lt;code&gt;encrypted_file.gpg&lt;/code&gt; and we can send to the recipient into S3, SFTP, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decrypt data with GPGME gem
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Must be have an imported recipient's private key.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;crypto&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'recipient_private_key.pgp'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Read and create Data instance of encrypted file
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;cipthertext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GPGME&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'encrypted_file.gpg'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Decrypt data and print
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decrypt&lt;/span&gt; &lt;span class="n"&gt;cipthertext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;
&lt;span class="c1"&gt;#last_name, name, mobile_phone\nSmith,Chris,3336985726&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>ruby</category>
      <category>rails</category>
      <category>pgp</category>
    </item>
    <item>
      <title>PGP - Create a Public/Private Key Pair(Part 2)</title>
      <dc:creator>Humberto Arroyo</dc:creator>
      <pubDate>Thu, 29 Sep 2022 14:19:30 +0000</pubDate>
      <link>https://dev.to/humbertoa6/pgp-create-a-publicprivate-key-pairpart-2-4a7b</link>
      <guid>https://dev.to/humbertoa6/pgp-create-a-publicprivate-key-pairpart-2-4a7b</guid>
      <description>&lt;p&gt;As we mention in the previous &lt;a href="https://dev.to/humbertoa6/pgp-encryptdecrypt-file-with-ruby-on-rails-part-3-3log"&gt;post&lt;/a&gt; PGP is a popular solution for encrypting, decrypting, signing, and verifying messages and files, often found in email communications and package repository identity verification (because security matters).&lt;/p&gt;

&lt;p&gt;In this post we'are gonna create Public/Private key pair to to encrypt and decrypt data.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Private key is a secret key that allows you to decrypt the messages.&lt;/li&gt;
&lt;li&gt;Public key encrypts data for a specific receiver.&lt;/li&gt;
&lt;li&gt;Install gnupg.&lt;/li&gt;
&lt;li&gt;Generate Public/Private key pair.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Secret key cryptography is effective for communication over insecure channels as the piece of information or parameter used helps the information to encrypt and decrypt messages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private key is a secret key that allows you to decrypt the messages&lt;/strong&gt; sent to you based on a public key. The private key can also be used to generate message and file signatures.&lt;/p&gt;

&lt;p&gt;Public key converts to encrypt data and it's uses asymmetric algorithms. A person who has a &lt;strong&gt;public key can encrypt the message intended for a specific receiver&lt;/strong&gt;. The receiver with the private key can only decode the message, which is encrypted by the public key. The public key is free to use. &lt;/p&gt;

&lt;p&gt;If Ana and John want to exchange a secret message, Ana (the sender) will encrypt the message using John's (the recipient) public key. When John receives the message, he will decrypt the message with his private key. No other parties can decrypt the message unless they have John's private key.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we can create GPG key pair keys?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install gnupg as our GPG client
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;gnupg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Generate a GPG key pair
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--full-generate-key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98i3no1yz9tdy011vdns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98i3no1yz9tdy011vdns.png" alt="Generate key pair GPG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;At the prompt, specify the &lt;strong&gt;RSA(Rivest-Shamir-Adleman)&lt;/strong&gt; key(option 1) and press Enter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the prompt, specify the key size you want, or press Enter to accept the default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the length of time the key should be valid. Press Enter to specify the default selection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter your user ID information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get Private key, signer(sender of encrypt file) should be an email example: &lt;a href="mailto:foo@foo.com"&gt;foo@foo.com&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--output&lt;/span&gt; private_key.pgp &lt;span class="nt"&gt;--armor&lt;/span&gt; &lt;span class="nt"&gt;--export-secret-key&lt;/span&gt; foo@foo.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get Public key:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--output&lt;/span&gt; public_key.pgp &lt;span class="nt"&gt;--armor&lt;/span&gt; &lt;span class="nt"&gt;--export&lt;/span&gt; foo@foo.com

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Optional: You can encode in base64 your key pherhaps to save in local environment. Run following command to get the private key encoded in base64
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;base64 &lt;/span&gt;private_key.pgp
//Output example: LS0tLS1CRUdJTiBQR1AgUFJJVkFURSBLRVkgQkxPQ0stLS0tLQoKbFFjWUJHTWphV0VC...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>encrypt</category>
      <category>decrypt</category>
      <category>security</category>
    </item>
    <item>
      <title>PGP - Introduction Encryption and Decryption (Part 1)</title>
      <dc:creator>Humberto Arroyo</dc:creator>
      <pubDate>Thu, 29 Sep 2022 14:17:43 +0000</pubDate>
      <link>https://dev.to/humbertoa6/pgp-introduction-encryption-and-decryption-part-1-440o</link>
      <guid>https://dev.to/humbertoa6/pgp-introduction-encryption-and-decryption-part-1-440o</guid>
      <description>&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Encryption converts plaintext into ciphertext.&lt;/li&gt;
&lt;li&gt;PGP is used for signing, encrypting, and decrypting information.&lt;/li&gt;
&lt;li&gt;Decryption converts encrypted data into original form.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In cryptography, &lt;strong&gt;encryption is the process of encoding information&lt;/strong&gt;. This process converts the original representation of the information(plaintext) into an alternative form known as ciphertext. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decryption is the conversion of encrypted data into original form&lt;/strong&gt;. It is generally a reverse process of encryption.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pretty Good Privacy (PGP)&lt;/strong&gt; is an encryption program that provides cryptographic privacy and authentication for data communication. &lt;strong&gt;PGP is used for signing, encrypting, and decrypting data&lt;/strong&gt;(texts, e-mails, files, directories, and whole disk partitions and to increase the security of e-mail communications) and allow us send and receive files securely. &lt;/p&gt;

&lt;p&gt;PGP and similar software follow the OpenPGP, an open standard of PGP encryption software, standard (RFC 4880) for encrypting and decrypting data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use case
&lt;/h2&gt;

&lt;p&gt;Ana and John are two people that want to exchange messages&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ana wants to send a private message&lt;/li&gt;
&lt;li&gt;John generates a public and a private key&lt;/li&gt;
&lt;li&gt;John keeps the private key and send back to Ana his public key&lt;/li&gt;
&lt;li&gt;Ana encrypts her message using John's public key&lt;/li&gt;
&lt;li&gt;Ana sends to John the encrypted message&lt;/li&gt;
&lt;li&gt;John decrypts the encrypted message with his private key&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wD9jhZQ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcfzubil0bvkdr4eyn4i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wD9jhZQ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcfzubil0bvkdr4eyn4i.png" alt="Encryption and Decryption" width="663" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Important&lt;/strong&gt;: If John(recipient) wants to receive encrypted message, it must generate key pair.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>encrypt</category>
      <category>decrypt</category>
      <category>security</category>
    </item>
    <item>
      <title>Antecedentes y razones para aprender JavaScript</title>
      <dc:creator>Humberto Arroyo</dc:creator>
      <pubDate>Tue, 06 Sep 2022 02:37:20 +0000</pubDate>
      <link>https://dev.to/humbertoa6/antecedentes-y-razones-para-aprender-javascript-4jj4</link>
      <guid>https://dev.to/humbertoa6/antecedentes-y-razones-para-aprender-javascript-4jj4</guid>
      <description>&lt;p&gt;Mocha es un lenguaje creado en 1995 por Brendan Eich, un programador de Netscape. Más tarde Mocha se convertiría JavaScript y fue creado para hacer pequeñas animaciones, interacciones a usuarios y otro tipo de situaciones para la web. &lt;/p&gt;

&lt;p&gt;Hoy, años después, el &lt;a href="https://w3techs.com/technologies/details/cp-javascript#:~:text=JavaScript%20is%20used%20as%20client,98.0%25%20of%20all%20the%20websites."&gt;98%&lt;/a&gt; de sitios web en internet usan JavaScript. Todo aquel que desea hacer una carrera en desarrollo web debe aprender JavaScript. &lt;/p&gt;

&lt;p&gt;A continuación te diré algunas razones para aprender JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Es el lenguaje de programación más popular&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Como mencioné anteriormente, JavaScript está en la mayoría de sitios web dentro de internet. Además, Stack Overflow lanza una &lt;a href="https://survey.stackoverflow.co/2022/#section-most-popular-technologies-programming-scripting-and-markup-languages"&gt;encuesta&lt;/a&gt; anualmente donde JavaScript se coloca como el lenguaje más popular por décimo año consecutivo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Es el lenguaje por default del internet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript es el lenguaje por default del internet y nativo de los navegadores, por lo cuál, no es necesario un IDE para programar en JavaScript. Si usted tiene acceso a un navegador web y a algún editor de texto, está configurado para probar su código dentro del navegador.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amigable para principiantes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La sintaxis de este lenguaje es más fácil comparado con otros lenguajes de programación. Además, tiene miles de recursos gratuitos y una gran comunidad que hace una excelente oportunidad para principiantes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lenguaje versátil&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Con JavaScript puedes aprender tanto Front-End como Back-End para el desarrollo web, lo que significa que no es necesario de otro lenguaje para crear sitios web completos.&lt;/p&gt;

&lt;p&gt;Desarrollo web no es el único campo de desarrollo de JavaScript, se pueden crear desktop apps con Electron o mobile apps con React native, los cuáles, son frameworks de JavaScript. &lt;/p&gt;

&lt;p&gt;Por otro lado, también se pueden crear apps para smartwatch, video juegos, VR(realidad virtual), AR(Realidad aumentada), etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alta demanda&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hoy en día con todo lo que la internet está expandiendo, provoca que haya una gran demanda de desarrolladores e incluso con muchas posiciones remotas y con salarios competitivos lo cuál lo hace interesante. Como lo mencioné anteriormente, JavaScript es el lenguaje más usado por décimo año consecutivo con un 65% y no veo como pueda ser remplazado.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Una gran comunidad&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Las comunidades juegan un gran papel dentro del aprendizaje, ya que los principales obstáculos que pueda usted enfrentar como principiante seguramente ya están resueltos. &lt;/p&gt;

&lt;p&gt;JavaScript tiene una gran comunidad en los sitios como Stack Overflow, GitHub, Reddit, Twitter, Slack, Discord, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Orientado al futuro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La gran cantidad de usuarios qué hay en internet día con día, hace que se necesiten de más desarrolladores para satisfacer las necesidades del mercado. Incluso, el lenguaje ha evolucionando cada año que hoy en día se implementa para tecnologías como VR, AR, inteligencia artificial, entre otros; ésto abre un camino inmenso de posibilidades hacia el futuro.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
