<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Christian Blais on Medium]]></title>
        <description><![CDATA[Stories by Christian Blais on Medium]]></description>
        <link>https://medium.com/@christ.blais?source=rss-1283a9af4adf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GOcC88fqjK1npfrr.</url>
            <title>Stories by Christian Blais on Medium</title>
            <link>https://medium.com/@christ.blais?source=rss-1283a9af4adf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 10:10:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christ.blais/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Time series charts powered by PostgreSQL]]></title>
            <link>https://medium.com/@christ.blais/time-series-charts-powered-by-postgresql-16bba7658eec?source=rss-1283a9af4adf------2</link>
            <guid isPermaLink="false">https://medium.com/p/16bba7658eec</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[charts]]></category>
            <dc:creator><![CDATA[Christian Blais]]></dc:creator>
            <pubDate>Thu, 08 Oct 2020 20:36:59 GMT</pubDate>
            <atom:updated>2020-10-13T13:39:14.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>Time series charts on PostgreSQL</h3><p><em>The following is an attempt at explaining my past self how to build basic time series using everyone’s favourite database, PostgreSQL. A fairly short and simple guide I wished I would have had as I was starting this project.</em></p><p>For the purpose of this exercise, let’s assume a simple table composed of two columns; an id and a timestamp. Let’s call it events.</p><pre>select * from events;</pre><pre>id |      timestamp     <br> — + — — — — — — — — — -<br> 1 | 2020–01–01 00:00:00<br> 2 | 2020–01–01 00:01:00<br> 3 | 2020–01–01 00:02:00<br> 4 | 2020–01–01 00:02:15<br> 5 | 2020–01–01 00:02:30<br> 6 | 2020–01–01 00:03:00<br> 7 | 2020–01–01 00:05:00</pre><p>The use case is simple; we need to group those events by time in an attempt to know how many of them occur within the same minute, with the end goal of generating a graph similar to the one below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0C3II5mF0xHdl0WNZpEn0w.png" /><figcaption>Events grouped by time</figcaption></figure><p>While this is probably the canonical example for a time series, there are a few tricks we need to know in order to get the desired result. First, we need to be able to group events by buckets of time (in this case, by their minute). Second, we need to leave no gaps behind, as even minutes with no event still need to be present. Finally, we need to only get events that are pertinent to the desired time frame. Let’s dissect it all.</p><h3>date_trunc</h3><p>The very first thing you’ll need to know is how to flatten a timestamp to its smallest unit of interest, which in our case is the minute. PostgreSQL offers the date_trunc function for exactly this purpose.</p><blockquote>Truncate a Date/Time to specified precision</blockquote><pre>select date_trunc(&#39;minute&#39;, timestamp) as minute FROM events;</pre><pre>        minute     <br>--------------------<br> 2020-01-01 00:00:00<br> 2020-01-01 00:01:00<br> 2020-01-01 00:02:00<br> 2020-01-01 00:02:00<br> 2020-01-01 00:02:00<br> 2020-01-01 00:03:00<br> 2020-01-01 00:05:00</pre><p>Such a function gives us the ability to ignore noise, leaving us only with what matters for our operations.</p><h3>group by</h3><p>Now that we have the ability to know at which minute a particular event happened, we can count them, and use that to generate our time series. A naive approach would be to group events by our newly created column, followed by a count.</p><pre>select date_trunc(&#39;minute&#39;, timestamp) as minute, count(*) FROM events group by minute;</pre><pre>       minute        | count <br>---------------------+-------<br> 2020-01-01 00:00:00 |     1<br> 2020-01-01 00:01:00 |     1<br> 2020-01-01 00:02:00 |     3<br> 2020-01-01 00:03:00 |     1<br> 2020-01-01 00:05:00 |     1</pre><p>While this works, it doesn’t create entries for minutes during which there were no event, as you can see with the missing 4th minute. This isn’t bad in itself, as you could leave it up to the application to fill in the blanks, but if we want to use the database as the only source of truth for our time series, this isn’t enough. We need to find a way to fill in those blanks.</p><h3>generate_series</h3><p>A better approach, at least for our use case, would be to list all the potential values, and then use those as the left hand side of a join with the events table. First thing first, let’s generate all the potential values. PostgreSQL offers a function called generate_series which does exactly this.</p><blockquote>generate_series generates a series of values, from start to stop with a step size of step</blockquote><pre>select generate_series(2,6,2);</pre><pre> generate_series<br>-----------------<br>               2<br>               4<br>               6</pre><p>As you can see, it works well with numbers, but it can just as easily work with times, too! We simply need a start time, an end time, as well as a time interval. Here, we need a series that would go from five minute ago (start time) to right now (end time), in increments of 1 minute (step). PostgreSQL offers various methods and functions which can help us here.</p><p>First, for the end time.</p><blockquote>The NOW() function returns the current date and time.</blockquote><pre>select now() at time zone &#39;UTC&#39; as end_time;</pre><pre>        end_time<br>-------------------------<br> 2020-01-01 00:05:00.0000</pre><p>Getting the step is also quite trivial.</p><blockquote>The interval data type allows you to store and manipulate a period of time in years, months, days, hours, minutes, seconds, etc.</blockquote><pre>select interval ‘1 minute’ as step;</pre><pre>   step<br> — — — — — <br> 00:01:00</pre><p>Using the two together means we can now get our starting time, too.</p><pre>select now() at time zone &#39;UTC&#39; - interval &#39;5 minute&#39; as start_time;</pre><pre>       start_time<br>-------------------------<br> 2020-01-01 00:00:00.0000</pre><p>The above, coupled with our knowledge on how to extract minutes out of dates, can then be leveraged to generate a series of timestamps.</p><pre>select generate_series(<br>  date_trunc(<br>    ‘minute’,<br>    now() at time zone &#39;UTC&#39;<br>  ) — interval ‘5 minutes’,<br>  date_trunc(<br>    ‘minute’,<br>    now() at time zone &#39;UTC&#39;<br>  ),<br>  interval ‘1 minute’<br>) as minutes;</pre><pre>       minutes         <br>------------------------<br> 2020-01-01 00:00:00 <br> 2020-01-01 00:01:00<br> 2020-01-01 00:02:00<br> 2020-01-01 00:03:00<br> 2020-01-01 00:04:00<br> 2020-01-01 00:05:00</pre><h3>join</h3><p>Great, we now have a list of all the minutes that exist within our time frame! We can now use this temporary table as the source of our join, and thus make sure we capture all the data we need.</p><pre>with intervals as (<br>  select generate_series(<br>    date_trunc(<br>      ‘minute’,<br>      now() at time zone &#39;UTC&#39;<br>    ) — interval ‘5 minutes’,<br>    date_trunc(<br>      ‘minute’,<br>      now() at time zone &#39;UTC&#39;<br>    ),<br>    interval ‘1 minute’<br>  ) as minutes<br>)</pre><pre>select<br>  intervals.minutes,<br>  count(events.*)<br>from intervals<br>left join events on<br>  intervals.minutes = date_trunc(&#39;minute&#39;, timestamp)<br>group by intervals.minutes<br>order by intervals.minutes;</pre><pre>       minute        | count <br>---------------------+-------<br> 2020-01-01 00:00:00 |     1<br> 2020-01-01 00:01:00 |     1<br> 2020-01-01 00:02:00 |     3<br> 2020-01-01 00:03:00 |     1<br> 2020-01-01 00:04:00 |     0<br> 2020-01-01 00:05:00 |     1</pre><p>And… that’s it! We can now use PostgreSQL as the sole source of our time series charts. Obviously, if you were to use this in production, you’d need to adjust for a time frame that makes sense for you, but hopefully this is enough to bootstrap your next project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16bba7658eec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is so “secure” about SecureRandom?]]></title>
            <link>https://medium.com/@christ.blais/what-is-so-secure-about-securerandom-776254f1ce1c?source=rss-1283a9af4adf------2</link>
            <guid isPermaLink="false">https://medium.com/p/776254f1ce1c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Christian Blais]]></dc:creator>
            <pubDate>Fri, 11 Nov 2016 04:44:19 GMT</pubDate>
            <atom:updated>2016-11-11T16:47:47.780Z</atom:updated>
            <content:encoded><![CDATA[<p>As you all know, Ruby comes with a variety of ways to generate random numbers; Random.new, Kernel.rand, the infamous <a href="https://github.com/jleeothon/forty-two">forty_two gem</a>. And then there’s SecureRandom. But why “secure”? Does it mean others are insecure by design?</p><p>Kernel.rand relies on a global, non-random seed generated when the Ruby process starts. The seed is fed to the default ruby pseudorandom number generator, which will keep track of it alongside its sequence position to output different random numbers.</p><pre>$ rand # seed: 2, sequence: 1<br>&gt; 0.43599490214200376<br>$ rand # seed: 2, sequence: 2<br>&gt; 0.025926231827891333</pre><p>You can also change the seed value with Kernel.srand, which will reset the state of the generator.</p><pre>$ srand 1<br>&gt; 2<br>$ rand # seed: 1, sequence: 1<br>&gt; 0.417022004702574</pre><p>Notice the return value of srand? It’s the value of the previous seed. It means that you can (or any other lib your in your project!) know how previous random numbers were generated, and even go as far as to reproduce them all by reseting the generator to its original state.</p><pre>$ srand 2<br>&gt; 1<br>$ rand # seed: 2, sequence: 1<br>&gt; 0.43599490214200376<br>$ rand # seed: 2, sequence: 2<br>&gt; 0.025926231827891333</pre><p>Random.new runs on the same principles, with the only difference that it lets you set a different seed on each object. Every instance of Random represents the pseudorandom number generator in a given state.</p><p>Knowing the state of the generator and being able to reset its state is useful in some circumstances and not bad in itself. Usages such as [1,2,3].sample are perfectly fine. But for anything sensitive such as passwords or session keys, it represents a serious vulnerability. Combine that with the non-random initial seed and you have something that is completely unsuitable for cryptography.</p><p>SecureRandom differs from other implementations by relying on OpenSSL and ultimately the operating system to generate randomness. The documentation states that Ruby supports three external secure random number generators;</p><ul><li>OpenSSL</li><li>/dev/urandom</li><li>Win32</li></ul><p>Since I’m no Windows user and OpenSSL only adds a layer of indirection on top of /dev/urandom, I’ll be focusing solely on the latter here, but all three offers more or less the same result.</p><p>So what the hell is /dev/urandom, and how can it be more secure than our built-in ruby generator? Turns out, the operating system has something that Ruby doesn’t have: an entropy pool.</p><blockquote>Entropy is the randomness collected by an operating system or application for use in cryptography or other uses that require random data. This randomness is often collected from hardware sources, either pre-existing ones such as mouse movements or specially provided randomness generators. (<a href="https://en.wikipedia.org/wiki/Entropy_(computing)">Source</a>)</blockquote><p>By collecting all sorts of non predictable events (called noise), such as mouse movements, keys typed, and files read, the operating system is able to generate an entropy pool that can later be consumed on demand. Each new event being computed on top of the previous ones, it technically creates an unpredictable entropy unique to each machine.</p><p>/dev/urandom is an interface to the kernel pseudorandom number generator, exposed as a readable device. When called, the generator uses entropy available in the pool to generate a stream of random bytes, adding the result back to the pool to make sure we never exhaust it. As an example, here’s how to read 10 random bytes;</p><pre>$ head -c 10 /dev/urandom | hexdump<br>&gt; 0000000 f2 a1 90 4d ec c2 a9 ac 72 cf</pre><p>SecureRandom.hex, base64, and random_number all rely on random_bytes, which reads bytes exactly as we just did, like we’d do for any other file. The <a href="https://github.com/ruby/ruby/blob/202bbda2bf5f25343e286099140fb9282880ecba/random.c#L431-L462">current implementation is in C</a>, but doesn’t differ that much from previous Ruby version. Shown below is a simplified version taken from Ruby 1.9.3.</p><pre>def self.random_bytes(n=nil)<br>  File.open(&quot;/dev/urandom&quot;, File::RDONLY) do|f|<br>    f.readpartial(n)<br>  end<br>end</pre><p>The resulting data is then simply massaged into the desired format depending on what method you called.</p><p>And that is why SecureRandom is considered secure. It still rely on a pseudorandom number generator as we would do in ruby land, but it has the benefit of using environmental noise, making it astronomically much more difficult to crack, and technically impossible without gathering the exact same environmental data.</p><p>Implementations may differ from one system to another. Linux offers both /dev/random and /dev/urandom (<a href="https://en.wikipedia.org/wiki//dev/random">learn the difference here</a>), OSX relies on a “SecurityServer” instead of an entropy pool and some recent Linux distributions offer a <a href="http://man7.org/linux/man-pages/man2/getrandom.2.html">getrandom(2)</a> system call to avoid having to read directly from the random device. But as much as they can differ, the core concept stays the same.</p><p>Thanks, and go have some cryptographic fun!</p><p><strong><em>Disclaimer:</em></strong><em> I’m no security expert. I wrote this article wanting to learn more about those concepts, but I do not guarantee any of this information. If you find mistakes or think I misunderstood some elements, please let me know.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=776254f1ce1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s the deal with Base64?]]></title>
            <link>https://medium.com/@christ.blais/whats-the-deal-with-base64-c93263b92dd6?source=rss-1283a9af4adf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c93263b92dd6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Christian Blais]]></dc:creator>
            <pubDate>Thu, 03 Nov 2016 03:56:37 GMT</pubDate>
            <atom:updated>2016-11-06T16:17:41.384Z</atom:updated>
            <content:encoded><![CDATA[<p>For the past few years, Base64 has been all around me. I used it to embed images in stylesheets, to safely (not securely!) transfer parameters over http, and more recently to make our GraphQL node IDs more opaque to API consumers. While I’ve always been familiar with its output, I never stopped to ask myself what was going on under the hood. Turns out, I should have.</p><p>At its core, Base64 takes binary data and turns it in an ASCII string. It doesn’t care about the original data, whether it was a UTF8 string or a PNG file; if it has bits, we’re good to go.</p><p>The goal of Base64 is to be able to safely transfer information from one system to another without loosing any data. It does so by using a set of 64 characters common to most encodings. While the actual set may differ in each implementation, the default Base64.encode64 ruby implementation uses a-z, A-Z, 0-9 as well as + and /. For URL or path encoding, you can also use Base64.urlsafe_encode, which replaces + and / with - and _. The set of characters doesn’t really matter, as long as both systems agree on a single set.</p><blockquote>Each base64 digit needs exactly 6 bits of information to be represented.</blockquote><p>The fact that we only use 64 characters is what make Base64 so interesting. We’re able to transform any set of potentially problematic characters (brackets, parenthesis, emojis, …) into a readable, printable string that most systems understand, avoiding any potential <a href="https://en.wikipedia.org/wiki/Delimiter#Delimiter_collision">delimiter collision</a>.</p><p>Following this <a href="https://en.wikipedia.org/wiki/Base64">Wikipedia example</a>, let’s try to convert a regular string into its Base64 format. First step, we need its binary representation.</p><pre>$ binary = &quot;Man&quot;.unpack(&#39;B*&#39;).first<br>&gt; &quot;010011010110000101101110&quot;</pre><p>Each character is encoded in their binary notation, for a total of 24 bits. Now, remember; Base64 only requires 6 bits per character. So instead of 3 groups of 8 bits, let’s consider this as 4 groups of 6 bits.</p><pre>$ base64 = binary.chars.each_slice(6).map(&amp;:join)<br>&gt; [&quot;010011&quot;, &quot;010110&quot;, &quot;000101&quot;, &quot;101110&quot;]</pre><p>Same bits, arranged differently. Now as stated at the beginning, Base64 takes binary data and turns it in an ASCII string. It does so by using a table for which each index maps to an ASCII character. A is at index 0, B at 1, all the way up to / at index 63. You can find the full table on the <a href="https://en.wikipedia.org/wiki/Base64">Wikipedia page</a>. All we have to do now is to convert those bit groups back into their decimal representation, and find their corresponding character.</p><pre>$ base64.map { |bits| bits.to_i(2) }<br>&gt; [19, 22, 5, 46]</pre><p>Mapping those integers with the table, we get T, W, F, and u. Guess what?</p><pre>$ Base64.encode64(“Man”)<br>&gt; &quot;TWFu&quot;</pre><p>That was easy, as 24 happily gets divided by 6. But Base64 works as well when it’s not the case, padding the last 24-bit block with 0, mapping those to the special = character. The number of = then indicates the number of missing bytes in those last 24 bits. Let’s see another example.</p><pre>$ binary = &quot;M&quot;.unpack(&#39;B*&#39;).first<br>&gt; &quot;01001101&quot;</pre><p>Obviously, since the string contains only one character, the “last” 24-bit block contains only 8 bits. It needs to be padded with 0.</p><pre>$ binary = binary.ljust(24, &quot;0&quot;)<br>&gt; &quot;010011010000000000000000&quot;</pre><p>The rest goes as usual, as we’re now able to build groups of 6 bits.</p><pre>$ base64 = binary.chars.each_slice(6).map(&amp;:join)<br>&gt; [&quot;010011&quot;, &quot;010000&quot;, &quot;000000&quot;, &quot;000000&quot;]<br>$ base64.map { |bits| bits.to_i(2) }<br>&gt; [19, 16, 0, 0]</pre><p>Mapping this against the table, we get T and Q, as well as two =.</p><pre>$ Base64.encode64(‘M’)<br>&gt; &quot;TQ==&quot;</pre><p>Decoding works the same, going through the same steps in reverse order. We map characters to their index in the table, grab the six relevant digits of their binary representation, join them together and voilà!, we have our original data back. Remember; Base64 doesn’t encrypt nor hash your data!</p><p>While first introduced to fix communication problems, Base64 is now widely used in HTML to avoid network calls, embedding images and fonts directly within the body of the page. Since the encoded string only represent a set of bytes, a header is usually attached to the content to let browsers know how to interpret the data.</p><pre>background: {<br>  url(data:image/gif;base64,R0lGODlhEA==)<br>}</pre><p>Javascript also allow encoding and decoding of Base64 data.</p><pre>encoded = btoa(&quot;hello&quot;) # binary to ascii<br>decoded = atob(encoded) # ascii to binary</pre><p>Of course, Base64 isn’t perfect. Being able to represent everything through a finite set of 64 characters means that everything takes more space. As we just saw, it encodes each set of three bytes into four bytes, in addition to the padding and the optional header. But for as long as we’ll have potential delimiter collisions, Base64 will likely stay around.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c93263b92dd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL, Rails and Global IDs]]></title>
            <link>https://medium.com/@christ.blais/graphql-rails-and-global-ids-c7b115d13660?source=rss-1283a9af4adf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7b115d13660</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[relayjs]]></category>
            <dc:creator><![CDATA[Christian Blais]]></dc:creator>
            <pubDate>Wed, 02 Nov 2016 03:42:56 GMT</pubDate>
            <atom:updated>2016-11-02T03:45:16.091Z</atom:updated>
            <content:encoded><![CDATA[<p>If you ever play with GraphQL, you’ll sooner or later need to load an arbitrary resource from the root query object. As an example, the <a href="https://facebook.github.io/relay/graphql/objectidentification.htm">Relay.js specification</a> asks that each identifiable resource expose a globally unique, standardized identifier. Such objects are referred to as nodes.</p><pre>query {<br>  node(id: &quot;globally unique id&quot;) {<br>    id<br>  }<br>}</pre><blockquote>The Node interface contains a single field, id, which is a ID!. The node root field takes a single argument, a ID!, and returns a Node. These two work in concert to allow refetching; if we pass the id returned in that field to the node field, we get the object back.</blockquote><p>Although the specification is clear on the intent, it doesn’t enforce nor provide any guidance as to how those identifiers should be created. In Rails, record IDs are scoped per table, or type-specific, hence aren’t considered globally unique. Given a single ID of 1, you wouldn’t know if you need to load #&lt;Post id: 1 ...&gt; or #&lt;Comment id: 1 ...&gt;.</p><p>Remember polymorphic associations? The problem was similar, in a sense that an association record could be of any type. Rails solved this by adding two columns, object_id and object_type, making it trivial to know to whom the ID belongs. However, the specification is clear here; only a single ID must be provided.</p><p>One interesting solution could be to reuse the same idea and combine the object type with the ID, producing a string similar to &quot;Post/1&quot;.</p><pre>query {<br>  node(id: &quot;Post/1&quot;) {<br>    id<br>  }<br>}</pre><p>We’d then be able to split the string server side and extract both the class name and the ID. The problem? We’d be reinventing the wheel.</p><p>Turns out, it isn’t the first time Rails has a need for a globally unique resource identifier. Back in 4.2, it introduced ActiveJob, a standardized interface for Sidekiq, Resque, and other queuing systems. One particularly interesting aspect of this interface is how jobs are queued, or should I say, what exactly get queued.</p><pre>$ PostTaggerJob.perform_later(Post.first)<br>$ YAML.load(Delayed::Job.first.handler).args<br>&gt; [PostTaggerJob, &quot;abc-1-xyz-2&quot;, &quot;gid://myApp/Post/1&quot;]</pre><p>These params represent the job class name, the job ID, and, you guessed it, a global identifier for the provided resource. In 4.2, alongside ActiveJob, Rails also introduced a gem called <a href="https://github.com/rails/globalid">GlobalID</a>, included by default in ActiveRecord.</p><blockquote>A Global ID is an app wide URI that uniquely identifies a model instance.</blockquote><pre>$ gid = Post.first.to_global_id<br>&gt; #&lt;GlobalID:0x007fa9add041f8 ...&gt;<br>$ gid.app<br>&gt; &quot;myApp&quot;<br>$ gid.model_name<br>&gt; &quot;Post&quot;<br>$ gid.model_class<br>&gt; Post(id: integer, name: string...)<br>$ gid.model_id<br>&gt; &quot;1&quot;<br>$ gid.to_s<br>&gt; &quot;gid://myApp/Post/1&quot;</pre><p>Obviously, the gem wouldn’t be complete without a way to retrieve our resources.</p><pre>$ GlobalID::Locator.locate(&quot;gid://myApp/Post/1&quot;)<br>&gt; #&lt;Post id: 1, name: &quot;GraphQL, Rails and Global IDs&quot; ...&gt;</pre><p>This is all we needed for GraphQL, as we’re now able to define unique resource identifiers in a standardized way.</p><pre>query {<br>  node(id: &quot;gid://myApp/Post/1&quot;) {<br>    id<br>  }<br>}</pre><blockquote>IDs are designed to be opaque (the only thing that should be passed to the id argument on node is the unaltered result of querying id on some object in the system), and base64ing a string is a useful convention in GraphQL to remind viewers that the string is an opaque identifier.</blockquote><p>Global IDs aren’t only useful for GraphQL and ActiveJobs. Since we can now uniquely identify resources everywhere in our application, it opens the door to better polymorphic drop-down list of options, better one-off access granting, resource sharing, and so on.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7b115d13660" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>