<?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: Sunny Pelletier</title>
    <description>The latest articles on DEV Community by Sunny Pelletier (@pelletier197).</description>
    <link>https://dev.to/pelletier197</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%2F862962%2F7f4f44f4-6f01-46cf-b305-67b3a7a1f5b8.png</url>
      <title>DEV Community: Sunny Pelletier</title>
      <link>https://dev.to/pelletier197</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pelletier197"/>
    <language>en</language>
    <item>
      <title>Why you need static documentation for your GraphQL API</title>
      <dc:creator>Sunny Pelletier</dc:creator>
      <pubDate>Tue, 17 May 2022 02:23:00 +0000</pubDate>
      <link>https://dev.to/pelletier197/why-you-need-static-documentation-for-your-graphql-api-19ol</link>
      <guid>https://dev.to/pelletier197/why-you-need-static-documentation-for-your-graphql-api-19ol</guid>
      <description>&lt;p&gt;One of the most important things for any API is documentation. Whether this API is used internally inside your company or is publicly available, developers interacting with it need a way to know how it works and what they can do with it.  &lt;/p&gt;

&lt;p&gt;In this article, I will go over how GraphQL compares to REST in this matter, the different types of documentation and finally, present the most common and standard way to document your API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Documenting: GraphQL vs REST
&lt;/h2&gt;

&lt;p&gt;Now I know what you're thinking: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"But I don't like to write documentation"&lt;/p&gt;

&lt;p&gt;-- &lt;cite&gt;Every developer ever&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Believe it, you're not alone. Nobody likes to write documentation. For this reason, lazy but smart developers had a brilliant idea: auto-generate it. &lt;/p&gt;

&lt;h3&gt;
  
  
  Documenting REST
&lt;/h3&gt;

&lt;p&gt;If you used REST before, there are many great tools that can do this, like &lt;a href="https://www.openapis.org/" rel="noopener noreferrer"&gt;Open-API&lt;/a&gt;, which generates a schema out of your endpoints. This schema can then be used to generate interactive or static documentation using &lt;a href="https://swagger.io/" rel="noopener noreferrer"&gt;Swagger-UI&lt;/a&gt; for instance. &lt;/p&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%2Fwstq1oxlybgt9go6f023.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%2Fwstq1oxlybgt9go6f023.png" alt="Swagger's logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  But what about GraphQL?
&lt;/h3&gt;

&lt;p&gt;GraphQL, unlike REST, doesn't need a tool like Open-API to generate a schema. It's built in!&lt;/p&gt;

&lt;p&gt;However, the schema does not really constitute a documentation in itself. There needs to be something that parses this schema and converts it to some sort of human-readable documentation for it to be useful. &lt;/p&gt;

&lt;h2&gt;
  
  
  Types of documentation
&lt;/h2&gt;

&lt;p&gt;Two different types of documentation were introduced earlier: static vs interactive. Let's go over each other to see their key differences. &lt;/p&gt;

&lt;h3&gt;
  
  
  Interactive documentation
&lt;/h3&gt;

&lt;p&gt;By interactive documentation, I mean a documentation that interacts with your API directly. &lt;a href="https://github.com/graphql/graphiql" rel="noopener noreferrer"&gt;GraphiQL&lt;/a&gt; is probably the most popular tool out-there to do this. &lt;/p&gt;

&lt;p&gt;This kind of documentation is great, because it allows developers to test their queries and see the results quite easily. It can also be referred to as a &lt;strong&gt;playground&lt;/strong&gt;, meaning that it's used to play around with the API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static documentation
&lt;/h3&gt;

&lt;p&gt;Static documentation, in opposition, does not interact with your API. It consists of static HTML pages that describes what is available and &lt;strong&gt;how&lt;/strong&gt; to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  But which one is better?
&lt;/h2&gt;

&lt;p&gt;To be fair, I was convinced that you did not need static documentation for GraphQL and that interactive docs were enough. That was until we actually started to have customers using our API. &lt;/p&gt;

&lt;p&gt;Even though they had a playground at their disposition, customers were not able to figure out everything else on their own. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do I authenticate? &lt;br&gt;
How do I fetch this particular information? &lt;br&gt;
Why do I get this error?&lt;br&gt;
What the hell is GraphQL?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What we realised very fast is that a playground was not enough. We needed to document authentication flows, concepts, common use-cases, etc. And all this is impossible to do with tools like GraphiQL alone. Interactive documentation is useful once you know exactly how to query something, but is not efficient at teaching you how to get there. &lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;The solution seemed very obvious: we need to use both. Both have their advantages, but together, they can do everything.&lt;/p&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%2Fez5kmh8xr9nkfdilexk6.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%2Fez5kmh8xr9nkfdilexk6.png" alt="Teamwork"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This may seem like a lot of extra-work, but this is actually the approach taken by many companies, like &lt;a href="https://docs.github.com/en/graphql" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; or &lt;a href="https://shopify.dev/api/admin-graphql/" rel="noopener noreferrer"&gt;Shopify&lt;/a&gt;. They provide a static API reference, along with a separated API explorer to test queries. &lt;/p&gt;

&lt;p&gt;And all this does not actually require that much work, because GraphQL does the heavy-lifting for you with its schema. &lt;/p&gt;

&lt;h2&gt;
  
  
  How ?
&lt;/h2&gt;

&lt;p&gt;So, for the interactive documentation, we simply decided to host an instance of GraphiQL that our customers can access if they want. &lt;/p&gt;

&lt;p&gt;As for the static documentation, branding was an important criteria for us. We did not want our documentation to look like everyone else's. &lt;/p&gt;

&lt;p&gt;Unfortunately, the existing open-source tooling was really not compatible with this need. The projects doing that were either unmaintained, almost impossible to customise or difficult to extend.  &lt;/p&gt;

&lt;p&gt;Given the circumstances, we took the initiative to create a new tool: A tool that would allow for extensive customisation, while also being simple to use. &lt;/p&gt;

&lt;p&gt;That's how &lt;a href="https://magidoc.js.org/introduction/welcome" rel="noopener noreferrer"&gt;Magidoc, a static GraphQL documentation website generator&lt;/a&gt; was born. With this project, we aim to provide various documentation templates and starters that are easily customisable to generate useful documentation for any GraphQL API.&lt;/p&gt;

&lt;p&gt;If you are interested in knowing more about it, learn how you can &lt;a href="https://medium.com/@sunnypelletier01/autogenerate-graphql-documentation-with-magidoc-53235f5d6dec" rel="noopener noreferrer"&gt;autogenerate GraphQL documentation for GraphQL using SDL files&lt;/a&gt;. To learn more about the tool itself, check out our &lt;a href="https://github.com/magidoc-org/magidoc" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;API Documentation is essential for any API that is used by someone else than you, whether these people are inside or outside your organisation. It makes people free to discover, understand and use your API without any other human help. &lt;/p&gt;

&lt;p&gt;GraphQL being pretty recent, there is not any standard on how to do it yet (and probably never will be). Static documentation combined with interactive documentation seems to be what most companies are leaning towards. As we are all different individuals and learn in different ways, some people will get started better using a playground and by playing with the API, while others will prefer to explore all the possibilities at a glance. &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>graphql</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
