<?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>Forem: 尤川豪</title>
    <description>The latest articles on Forem by 尤川豪 (@howtomakeaturn).</description>
    <link>https://forem.com/howtomakeaturn</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%2F110909%2F11630345-5c0b-4cfd-908f-01b2279c0fe3.jpeg</url>
      <title>Forem: 尤川豪</title>
      <link>https://forem.com/howtomakeaturn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/howtomakeaturn"/>
    <language>en</language>
    <item>
      <title>Test post 2</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Sun, 19 May 2024 01:50:20 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/test-post-2-h4f</link>
      <guid>https://forem.com/howtomakeaturn/test-post-2-h4f</guid>
      <description>&lt;p&gt;This is a testing post&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Test post 1</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Sun, 19 May 2024 01:50:12 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/test-post-1-34j0</link>
      <guid>https://forem.com/howtomakeaturn/test-post-1-34j0</guid>
      <description>&lt;p&gt;this is a testing post&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My freelancing experience with Laravel + GraphQL Part 2: How to use Query/Mutation in frontend with React.js</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Mon, 20 Nov 2023 02:45:03 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/my-freelancing-experience-with-laravel-graphql-part-2-how-to-use-querymutation-in-frontend-with-reactjs-2j60</link>
      <guid>https://forem.com/howtomakeaturn/my-freelancing-experience-with-laravel-graphql-part-2-how-to-use-querymutation-in-frontend-with-reactjs-2j60</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclsmqgo1ogo5tc4sv0jc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclsmqgo1ogo5tc4sv0jc.png" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the previous article, I introduced the strength of GraphQL and how to implement it in Laravel&lt;/p&gt;

&lt;p&gt;Let's talk about how to use it in frontend with React.js today!&lt;/p&gt;

&lt;h2&gt;
  
  
  Example project and API playground
&lt;/h2&gt;

&lt;p&gt;I implemented an e-commerce sample project with graphql + laravel in the previous post&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-laravel-example.tw/graphiql"&gt;https://graphql-laravel-example.tw/graphiql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a simple e-commerce frontend with Next.js this time&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-react-example.vercel.app/"&gt;https://graphql-react-example.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can browse products &amp;amp; subscribe the newsletter in the web app!&lt;/p&gt;




&lt;p&gt;For &lt;code&gt;graphql query&lt;/code&gt; sample code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-react-example/blob/main/app/page.js"&gt;https://github.com/howtomakeaturn/graphql-react-example/blob/main/app/page.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;graphql mutation&lt;/code&gt; sample code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-react-example/blob/main/app/newsletter.js"&gt;https://github.com/howtomakeaturn/graphql-react-example/blob/main/app/newsletter.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I use the native &lt;code&gt;fetch&lt;/code&gt; function to call graphql api, so you should be able to do it with any http libraries.&lt;/p&gt;

&lt;p&gt;And I use &lt;code&gt;swr&lt;/code&gt; library (Next.js official library) as state manager, but any state manager should be fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Strengths
&lt;/h2&gt;

&lt;p&gt;The best part about graphql is frontend devs can decide what data should be returned!&lt;/p&gt;

&lt;p&gt;Frontend devs can try &amp;amp; see the results with the powerful graphql playground&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-laravel-example.tw/graphiql"&gt;https://graphql-laravel-example.tw/graphiql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even relational data can be returned easily!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const gql = `query {
  products {
    id
    name
    description
    featured_image
    price
    comments {
      content
      user {
        name
      }
    }
  },
}`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reduces devlopment time and communication time a lot!&lt;/p&gt;

&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;React source code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-react-example"&gt;https://github.com/howtomakeaturn/graphql-react-example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Laravel backend sample project&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-laravel-example.tw/"&gt;https://graphql-laravel-example.tw/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Laravel backend source code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-laravel-example"&gt;https://github.com/howtomakeaturn/graphql-laravel-example&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;With the above example projects,&lt;/p&gt;

&lt;p&gt;You should be able to implement your own graphql APIs in your project!&lt;/p&gt;

&lt;p&gt;I will realease more sample code in the following articles, you should definitely give graphql a try!&lt;/p&gt;

&lt;p&gt;(This is series article. More content will be released soon.)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My freelancing experience with Laravel + GraphQL Part 1: Strengths, API playground, and tools intro (Sample code included!)</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Thu, 02 Nov 2023 02:27:57 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/my-freelancing-experience-with-laravel-graphql-part-1-strengths-api-playground-and-tools-intro-sample-code-included-1g9p</link>
      <guid>https://forem.com/howtomakeaturn/my-freelancing-experience-with-laravel-graphql-part-1-strengths-api-playground-and-tools-intro-sample-code-included-1g9p</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i381o5zdoz29p9bld4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i381o5zdoz29p9bld4o.png" alt="Grpahql" width="800" height="343"&gt;&lt;/a&gt;&lt;br&gt;
In the past few months, I helped one of my clients to refactor their legacy laravel project into a SPA architecture.&lt;/p&gt;

&lt;p&gt;We use GraphQL to get better DX (developer experience) and reduce communication cost between frontend devs and backend devs.&lt;/p&gt;

&lt;p&gt;It turns out to be a huge success! The dev team is quite happy with the result!&lt;/p&gt;

&lt;p&gt;Today I want to share some experiences &amp;amp; some sample code!&lt;/p&gt;

&lt;h2&gt;
  
  
  Strengths
&lt;/h2&gt;

&lt;p&gt;My favorite part about graphql is that the communication between frontend devs and backend devs becomes much easier!&lt;/p&gt;

&lt;p&gt;When the backend devs finish the backend part, graphql automatically generates API documentation &amp;amp; testing tools!&lt;/p&gt;

&lt;p&gt;For better demonstration, I create a sample project on Github!&lt;/p&gt;

&lt;p&gt;It's a simple e-commerce project, with &lt;code&gt;products&lt;/code&gt; and &lt;code&gt;comments&lt;/code&gt; in the API.&lt;/p&gt;

&lt;p&gt;And users can subscribe to the newsletter, insert new data into the &lt;code&gt;subscribers&lt;/code&gt; type!&lt;/p&gt;

&lt;h2&gt;
  
  
  Example project and API playground
&lt;/h2&gt;

&lt;p&gt;The project link is here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-laravel-example.tw/"&gt;https://graphql-laravel-example.tw/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The source code is here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-laravel-example"&gt;https://github.com/howtomakeaturn/graphql-laravel-example&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;In graphql, for 'reading data' APIs, we call it 'query'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-laravel-example/tree/main/app/GraphQL/Queries"&gt;https://github.com/howtomakeaturn/graphql-laravel-example/tree/main/app/GraphQL/Queries&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For 'updating data' APIs, we call it 'mutation'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/howtomakeaturn/graphql-laravel-example/tree/main/app/GraphQL/Queries"&gt;https://github.com/howtomakeaturn/graphql-laravel-example/tree/main/app/GraphQL/Queries&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out the above folders, you can see each API is a single file, makes its very easy to understand.&lt;/p&gt;

&lt;p&gt;And then you can try out the powerful tool 'graphiql' - it provides documentation &amp;amp; testing tool at the same time!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphql-laravel-example.tw/graphiql"&gt;https://graphql-laravel-example.tw/graphiql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I deploy a sample graphiql online so you can play with it directly!&lt;/p&gt;

&lt;p&gt;This tool is my favorite thing in the graphql ecosystem!&lt;/p&gt;

&lt;h2&gt;
  
  
  Packages
&lt;/h2&gt;

&lt;p&gt;There's two way of implementing api in graphql: schema-first and code-first.&lt;/p&gt;

&lt;p&gt;For schema-frst with laravel, you can use&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nuwave/lighthouse"&gt;https://github.com/nuwave/lighthouse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For code-first with laravel, you can use&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rebing/graphql-laravel"&gt;https://github.com/rebing/graphql-laravel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won't mention the differences between the two ways here.&lt;/p&gt;

&lt;p&gt;I personally prefer code-first philosophy. I think it's easier to understand &amp;amp; implement.&lt;/p&gt;

&lt;p&gt;So I'll use &lt;a href="https://github.com/rebing/graphql-laravel"&gt;https://github.com/rebing/graphql-laravel&lt;/a&gt; in the example project.&lt;/p&gt;

&lt;p&gt;They both use &lt;a href="https://github.com/webonyx/graphql-php"&gt;https://github.com/webonyx/graphql-php&lt;/a&gt; as the fundamental components&lt;/p&gt;

&lt;p&gt;So don't worry, they share the same core concepts!&lt;/p&gt;




&lt;p&gt;Graphiql is a graphql official library.&lt;/p&gt;

&lt;p&gt;Use &lt;a href="https://github.com/mll-lab/laravel-graphiql"&gt;https://github.com/mll-lab/laravel-graphiql&lt;/a&gt; to install it easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;With the above packages &amp;amp; the example project I provided &lt;a href="https://github.com/howtomakeaturn/graphql-laravel-example"&gt;https://github.com/howtomakeaturn/graphql-laravel-example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be able to implement your own graphql APIs in your project!&lt;/p&gt;

&lt;p&gt;I will realease more sample code in the following articles, so you won't get blocked by the advanced features with graphql!&lt;/p&gt;

&lt;p&gt;(This is series article. More content will be released soon.)&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>graphql</category>
    </item>
    <item>
      <title>test mention feature</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Thu, 27 Apr 2023 02:25:08 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/test-mention-feature-1e02</link>
      <guid>https://forem.com/howtomakeaturn/test-mention-feature-1e02</guid>
      <description>&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/howtomakeaturn"&gt;@howtomakeaturn&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;@testtest333&lt;/p&gt;

</description>
    </item>
    <item>
      <title>test post</title>
      <dc:creator>尤川豪</dc:creator>
      <pubDate>Thu, 14 Feb 2019 10:53:00 +0000</pubDate>
      <link>https://forem.com/howtomakeaturn/test-post-3jp2</link>
      <guid>https://forem.com/howtomakeaturn/test-post-3jp2</guid>
      <description>

&lt;h1&gt;
  
  
  haha
&lt;/h1&gt;

&lt;p&gt;this is a testing post&lt;/p&gt;


</description>
      <category>fortesttag</category>
    </item>
  </channel>
</rss>
