<?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 Marcus Stenbeck on Medium]]></title>
        <description><![CDATA[Stories by Marcus Stenbeck on Medium]]></description>
        <link>https://medium.com/@marcusstenbeck?source=rss-5ab4c129c860------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-IXIWBZ-QLwxGfXM.jpeg</url>
            <title>Stories by Marcus Stenbeck on Medium</title>
            <link>https://medium.com/@marcusstenbeck?source=rss-5ab4c129c860------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:14:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcusstenbeck/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[Show Calendar — Part 0: Intro & Starter Kit]]></title>
            <link>https://medium.com/@marcusstenbeck/show-calendar-part-0-intro-starter-kit-ad9a07c43f6d?source=rss-5ab4c129c860------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad9a07c43f6d</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[cqrs]]></category>
            <dc:creator><![CDATA[Marcus Stenbeck]]></dc:creator>
            <pubDate>Thu, 18 Jan 2018 07:30:03 GMT</pubDate>
            <atom:updated>2018-01-18T07:30:03.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agC3T4GxiEOb-S_DCBy_5g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/ZBD7Wh3SJEI?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Josh Felise</a> on <a href="https://unsplash.com/search/photos/sunrise?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The Show Calendar project explores developing an app with the Event Sourcing and CQRS patterns. The goal is to understand how good these patterns are for fast-changing projects, like startups.</p><p>The project is implemented in JavaScript with a GraphQL API, but the ideas should work in any language.</p><h3>Why?</h3><p>One day I ran into <a href="https://www.youtube.com/watch?v=rUDN40rdly8">a talk by Greg Young’s about Event Sourcing</a>, and the concept was super interesting to me. In short, Event Sourcing means that you store all events that happen in your app.</p><blockquote><em>Event Sourcing done right allows you to recreate your app’s state at </em>any point in time<em>.</em></blockquote><p>By <em>replaying</em> your events you can recreate your database… but if you think about it, the contents of your database is only a result of all the events that have happened.</p><p>Having a log of events isn’t a new idea — banks have been doing this for ages. The bank records each change to your bank account in a ledger, and the amount of money in your account is a result of all the entries in that ledger.</p><p>The result of producing a value by looking at every recorded event is sometimes called a <em>projection</em>. Events are <em>projected</em> onto a projection, and a projection can be whatever you want — a bank account balance or your app’s database contents.</p><blockquote><em>The contents of your database is only one way of looking at the event history.</em></blockquote><p>It turns out that having a record of all the events that have happened in you app — or business — allows you to view those events in different ways.</p><blockquote><em>You’ll be able to reinterpret history if you keep a record of what lead up to it.</em></blockquote><p>That’s <em>super interesting</em> from a “startup-y” perspective.</p><p>If there’s anything certain about new ventures it is that, for most things, we’re not really certain. And from a coding perspective this means we have to be flexible. Event Sourcing might help us achieve some of that flexibility by giving us the the option to “reinterpret” history.</p><p>And this is the reason I’m interested in exploring Event Sourcing from a “startup perspective” where refactoring and flexibility is important.</p><p><em>I was introduced to the “Event Sourcing is good for startups” hypothesis by Mike Mogosanu of Sapiensworks in his article </em><a href="http://blog.sapiensworks.com/post/2017/10/30/Is-DDD-ES-CQRS-changing-domain.html"><em>Using DDD, CQRS, Event Sourcing With A Vague, Fast Changing Domain</em></a><em>.</em></p><h3>Node.js / GraphQL Starter Kit</h3><p><a href="https://github.com/marcusstenbeck/show-calendar/tree/part-0/boilerplate"><em>Download the starting point project files from GitHub.</em></a></p><p>Install dependencies with npm install and then start the server with npm start. The server is then available on http://localhost:3000 and has the following two routes.</p><ul><li>/graphql - GraphQL API endpoint</li><li>/graphiql - GraphiQL (&lt;- notice the i) playground</li></ul><h3>Why am I using GraphQL for this project?</h3><p>GraphQL’s Query and Mutation types map really nicely onto the CQRS pattern&#39;s <em>Query</em> and <em>Command</em> concepts. In addition to that, the GraphiQL playground is a really nice way to test the API as we go.</p><p>Next: <a href="https://medium.com/@marcusstenbeck/show-calendar-part-1-setting-up-the-api-89c4b55234df">Part 1: Setting Up the API</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad9a07c43f6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Show Calendar — Part 2: Implementing Event Sourcing (for Dummies!)]]></title>
            <link>https://medium.com/@marcusstenbeck/part-2-implementing-event-sourcing-for-dummies-ffc11dc3dcc?source=rss-5ab4c129c860------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffc11dc3dcc</guid>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Marcus Stenbeck]]></dc:creator>
            <pubDate>Wed, 17 Jan 2018 20:08:26 GMT</pubDate>
            <atom:updated>2018-01-17T21:20:53.552Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The Show Calendar project explores developing an app with the Event Sourcing and CQRS patterns. The goal is to understand how good these patterns are for fast-changing projects, like startups.</em></p><p><em>The project is implemented in JavaScript with a GraphQL API, but the ideas should work in any language.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87Vmpm3Bbd1E6djZeHUupQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/52p1K0d0euM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Austris Augusts</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In <a href="https://medium.com/@marcusstenbeck/show-calendar-part-1-setting-up-the-api-89c4b55234df">Part 1</a> we created a GraphQL API that allows us to list all existing shows and add new shows, only… it didn’t really allow us to add shows. Mock data is only so much fun.</p><p>Now it’s time to remove the mock data and implement a super basic, but functional, event sourced backend.</p><p>Where we left off in the previous article, the resolver functions just straight up return literal values. What we need to do now is create two functions getShows() and addshow() that we&#39;ll use in our GraphQL resolver functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14ab8256f1726e6640122c7c84e4f2e2/href">https://medium.com/media/14ab8256f1726e6640122c7c84e4f2e2/href</a></iframe><p>There’s an opportunity right here to create some structure in the project — so let’s move the addShow() and getShows() functions into their own files.</p><p>Remember, addShow() is a <strong>Command</strong>—so let&#39;s put it in src/commands/addShow.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f9d2218f67e7a8ec546da8b3653d33a/href">https://medium.com/media/1f9d2218f67e7a8ec546da8b3653d33a/href</a></iframe><p>And since getShows() is a <strong>Query</strong> it goes in src/queries/getShows.js. We&#39;ll return an empty array for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/106462fbda8f94c9a5039fcc193122a2/href">https://medium.com/media/106462fbda8f94c9a5039fcc193122a2/href</a></iframe><h3>The AddShow Command</h3><p>In order to add a show we need to do two things.</p><ol><li>Ensure the data values are good (“business logic”).</li><li>Save an event that says we added the show (we’ll call this “committing an event”).</li></ol><p>Perhaps a bit backwards, I’ll explain events first and then the business logic stuff.</p><h3>What is an event?</h3><p>An <em>event</em> can be defined in tons of ways, but we’re going to be pretty specific about it. Our definition has one simple requirement for naming.</p><blockquote><em>Events should always be named in past-tense.</em></blockquote><p>What’s the point of that? Why should we name an event ShowAdded instead of AddShow?</p><blockquote><em>Events are things that </em>have already happened<em>.</em></blockquote><p>I struggled to understand this when first learning about Event Sourcing.</p><p>It’s simply a convention <em>(that you can choose to ignore!)</em> that helps us <em>be sure</em> the event log only contains things that have <em>already happened</em>. Knowing for sure that something has happened makes it easier to reason about the meaning of our events.</p><p>Linking it to our commands and queries might make it clearer.</p><blockquote><strong><em>Commands</em></strong><em> should </em>determine if an event can happen<em> </em><strong><em>and then</em></strong><em> </em>save the event to the event log<em> </em><strong><em>or</em></strong><em> </em>throw an error<em>.</em></blockquote><blockquote><strong><em>Queries</em></strong><em> should </em>return a value based on the events in the event log<em>.</em></blockquote><p>Let’s think about what events mean for our queries. Imagine we have a stream like this:</p><ol><li>ADD_SHOW</li><li>SHOW_ADDED</li><li>ADD_SHOW</li><li>SHOW_ADDED</li></ol><p>It should be safe to assume that ADD_SHOW and SHOW_ADDED contains the same type of data—that they come in pairs... so <em>one</em> of them might be redundant.</p><ul><li>If we keep only ADD_SHOW we can answer the question &quot;Which shows were we asked to add?&quot;</li><li>If we instead keep only SHOW_ADDED we can answer the question &quot;Which shows have we added?&quot;</li></ul><p>The answer to both questions might be interesting, and if it’s important to know both answers we can leave both variants.</p><p>But is ADD_SHOW really an event? The name ADD_SHOW implies that something should happen... and that sounds a lot like it&#39;s a command, right?</p><p>So, when we store ADD_SHOW what we&#39;re really storing isn&#39;t an event, but rather a command. When we mix commands (desired future) and events (certain past) it&#39;s no longer clear what to do with the stored value. Should ADD_SHOW add something to our app&#39;s state, or should we ignore it?</p><p>Only storing events makes it straightforward to interpret what the event means — something has happened that’s important enough that we need to keep track of it.</p><p><em>(If you’re curious, storing only commands is also a concept, and it’s called Command Sourcing.)</em></p><p>If you really <em>really</em> <em>REALLY</em> want to be able to differentiate between when a user started to add a show until it was added then you could avoid the confusion by naming the event something like STARTED_ADDING_SHOW.</p><p>Hopefully the above is enough to convince you that it’s a good idea to name events in past-tense.</p><p>… <em>RANT_ENDED</em>.</p><h3>Let’s implement addShow()</h3><p>The command for adding a show will produce an event with the following shape.</p><pre>ShowAdded {  <br>  title: String<br>  time: DateTime<br>  host: String<br>  location: String<br>}</pre><p>Earlier I mentioned that commands should handle business logic, like validating data. Let’s say we have two business requirements.</p><ol><li>The fields title, host and location must exist and be at most 50 characters long.</li><li>date must be a Date object.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2271df16924ccbcb486a0279e0ca424a/href">https://medium.com/media/2271df16924ccbcb486a0279e0ca424a/href</a></iframe><p>At the end of the addShow() function we should now be certain that the incoming data fulfills our business requirements and that we&#39;re ready to commit a ShowAdded event to the event history... but where do we save it?</p><p>The answer is… the event store.</p><h4>Adding Events to the Event Store</h4><p>I’m going to let the code speak for itself for our minimal event store implementation. Go ahead and put the below code in src/event-store/index.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7a52ed35bf2af66a4cace94950f7c5e/href">https://medium.com/media/e7a52ed35bf2af66a4cace94950f7c5e/href</a></iframe><p>The function createStore() creates an object that has one function commit(event). Calling commit(event) appends the event to the internal array events.</p><p>We could add a ton more functionality, but since we’re aiming to learn, this naive implementation is good enough. We’ll just have to trust that we <em>Do The Right Thing™</em> and only add properly formatted events (e.g. don’t <em>ever</em> use this in production).</p><p>In order to share the event store between commands and queries, e.g. addShow()and getShows(), we&#39;ll pass it as an argument to the command/query functions.</p><p>Let’s update src/commands/addShow.js to use the event store.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/703f79d69a819ac395a4051d0a7a24e9/href">https://medium.com/media/703f79d69a819ac395a4051d0a7a24e9/href</a></iframe><p>The last step before being able to add shows to the event store is to update our GraphQL resolver with two changes.</p><ol><li>Import addShow(), getShows() and createStore().</li><li>Create the event store.</li><li>Pass the event store to the queries and commands.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e6a49d5cff99419bc6be8ff410574ee/href">https://medium.com/media/8e6a49d5cff99419bc6be8ff410574ee/href</a></iframe><p>Now we can add shows, but we still need to make the query return the list of added shows.</p><h3>The GetShows Query</h3><p>Let’s update the getShows() query so it returns the list of shows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e878eb85d7860cc9d947d410b666afd9/href">https://medium.com/media/e878eb85d7860cc9d947d410b666afd9/href</a></iframe><p>For this simple case we add the payload of each ShowAdded event to an array and then return it. Later we might need more advanced checks, for example if we have events that edits or deletes shows, but that&#39;s for a later article.</p><p>If you paid attention you noticed that the code above called getEvents() (line 2) on the event store, but this function doesn&#39;t yet exist. Let&#39;s add it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1322e5391c3c1a8db2022cd8451fa371/href">https://medium.com/media/1322e5391c3c1a8db2022cd8451fa371/href</a></iframe><p>And since we already updated the GraphQL resolvers to pass the event store to getShows() we&#39;re done!</p><h3>Now, play.</h3><p>Go ahead and run the GraphQL queries again, using the GraphiQL playground (<a href="https://stenbeck.io/part-2-implementing-event-sourcing/">localhost:3000/graphiql</a>). Here’s the queries from my previous article.</p><pre>query GetShows {<br>  allShows {<br>    title<br>    time<br>    host<br>    location<br>  }<br>}</pre><pre>mutation AddShow {<br>  addShow(<br>    title: &quot;Trolling&quot;<br>    time: &quot;2018-04-01T13:37:00Z&quot;<br>    host: &quot;Trollface&quot;<br>    location: &quot;Reddit&quot;<br>  )<br>}</pre><h3>Summing it up</h3><p>There’s a lot more to cover, like how we handle updates and deletes <em>(hint: it’s by adding more events!)</em> and how we can avoid going through the entire event history on every query, but this is a fully functioning event sourced backend.</p><p>I hope you’re as inspired as I was when I first learned about Event Sourcing. It really opens up a new angle of implementing systems, and it’s being used to orchestrate all sorts of things across microservices. Our example is simplified to the extreme, and I’m sure you can imagine where you’d want to go from here for your projects <em>(like adding databases, or in-memory caches, or versioning the events to help with concurrency, or…)</em>.</p><p>And for any frontend devs that have used Redux — I know — CQRS is basically like Redux and Event Sourcing is kinda like the Redux Dev Tools… which was what initially drew me in.</p><p>Please let me know (<a href="https://twitter.com/marcusstenbeck">@marcusstenbeck</a>) what you think and/or what more you’d want me to explore further. Thanks for reading!</p><p>If you didn’t code along you can browse around the code in my <a href="https://github.com/marcusstenbeck/show-calendar">show-calendar repo</a>.</p><p>Previous: <a href="https://medium.com/@marcusstenbeck/show-calendar-part-1-setting-up-the-api-89c4b55234df">Part 1: Setting Up the API</a><br>Next: Part 3: <em>To be determined</em></p><p><strong>A note on Commands not returning a value:</strong> You may have noticed and questioned why the command doesn’t return anything. I wrote a short article (<a href="https://stenbeck.io/commands-vs-events/">link</a>) explaining why, but in short it’s because commands should only determine if an event is possible given the input data and current circumstances, and then commit that event to history. Actually writing to a database or doing something else is the consequence of committing an event to history.</p><p>So, in our case, how do we get the updated show list?</p><p>Simple, <em>use the queries.</em> Or implement something even cooler, like a GraphQL subscription that notifies the frontend of the change.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffc11dc3dcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Show Calendar — Part 1: Setting Up the API]]></title>
            <link>https://medium.com/@marcusstenbeck/show-calendar-part-1-setting-up-the-api-89c4b55234df?source=rss-5ab4c129c860------2</link>
            <guid isPermaLink="false">https://medium.com/p/89c4b55234df</guid>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marcus Stenbeck]]></dc:creator>
            <pubDate>Sun, 14 Jan 2018 12:11:24 GMT</pubDate>
            <atom:updated>2018-01-18T07:34:23.762Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The Show Calendar project explores developing an app with the Event Sourcing and CQRS patterns. The goal is to understand how good these patterns are for fast-changing projects, like startups.</em></p><p><em>The project is implemented in JavaScript with a GraphQL API, but the ideas should work in any language.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xogswwFaYI6MbrbNXhUKew.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/3_I4NVI9d1k?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Randall Bruder</a> on <a href="https://unsplash.com/search/photos/cables?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>We’re going to set up a GraphQL API that’ll serve as our entry point into the show calendar system.</p><p>The first step I usually take when starting my implementation is to think of the data model.</p><h3>The Show data model</h3><p>I want to keep it simple — we don’t need anything fancier than a single type Show. Yes, we could have a more advanced data model, but in the name of simplicity, this is a reasonable starting point.</p><pre>Show {  <br>  title: String<br>  time: DateTime<br>  host: String<br>  location: String<br>}</pre><p><em>I know this model has problems.</em> For example, a show may, in reality, have more than one host. But instead of planning for that I’m going to later introduce it as a <em>change of requirements</em>. One of the points of this project is to see how easy or hard it is to handle this type of change.</p><p>(It’ll be interesting to see how things go… especially if there’s a pre-existing “legacy database” with a bunch of data that was added before we “knew” about the “new” requirement. <em>Alas, onwards!</em>)</p><h3>CQRS… ?</h3><p>We’re going to apply the <em>Command Query Responsibility Separation</em> pattern, or <em>CQRS</em>. This means splitting the functionality of reading and writing <em>(e.g. creating, reading, updating)</em> into separate things — <em>Queries</em> and <em>Commands</em>.</p><blockquote><strong><em>Queries</em></strong><em> are for reading data.</em></blockquote><blockquote><strong><em>Commands</em></strong><em> are for writing data.</em></blockquote><p>Our system will be simple and have only one query.</p><pre>## Show Calendar Queries ##<br>GetShow -&gt; Shows</pre><p>The most basic command in the system is adding a show. For the time being we have no business rules. In other words, we can add multiple shows with exactly the same information.</p><pre>## Show Calendar Commands ##<br>AddShow(title, time, host, location) -&gt; void</pre><p>And that’s it for now. Later on we might add more commands or queries, but for simplicity’s sake this is enough.</p><h3>It’s coding time!</h3><p>Implementing stuff always makes me understand things better. The Show Calendar app will be implemented in Node.js with a GraphQL API.</p><p><em>If you haven’t already, get the starter kit here: </em><a href="https://stenbeck.io/show-calendar-part-1-api/"><em>Part 0 — Starter Kit</em></a><em>.</em></p><h3>Set up the GraphQL API</h3><p>In src/schema/index.js, set up one query allShows and one mutation addShow. At the same time, add the Show GraphQL type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ab2894761169f2bab59598abdbeaa9e/href">https://medium.com/media/0ab2894761169f2bab59598abdbeaa9e/href</a></iframe><p>The CQRS pattern’s <em>Query</em> and <em>Command</em> concepts map really nicely onto GraphQL’s <em>Query</em> and <em>Mutation</em> types.</p><blockquote><em>CQRS </em><strong><em>Query</em></strong><em> — GraphQL </em><strong><em>Query</em></strong></blockquote><blockquote><em>CQRS </em><strong><em>Command</em></strong><em> — GraphQL </em><strong><em>Mutation</em></strong></blockquote><p>Now, start the server with npm start and go to the GraphiQL playground (<a href="https://localhost:3000/graphiql">localhost:3000/graphiql</a> - <em>don&#39;t forget the the </em><em>i!)</em> and paste the below query and mutation.</p><p><em>Note: </em><em>npm start from the starter kit will automatically restart the server when it detect that you&#39;ve saved a code change. No need to start and stop!</em></p><pre>query GetShows {<br>  allShows {<br>    title<br>    time<br>    host<br>    location<br>  }<br>}</pre><pre>mutation AddShow {<br>  addShow(<br>    title: &quot;Trolling&quot;<br>    time: &quot;2018-04-01T13:37:00Z&quot;<br>    host: &quot;Trollface&quot;<br>    location: &quot;Reddit&quot;<br>  )<br>}</pre><p>Using the play button, run the GetShows query and you should receive the following response.</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;allShows&quot;: []<br>  }<br>}</pre><p>Running the AddShow mutation should result in the following.</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;addShow&quot;: true<br>  }<br>}</pre><p>However, if you run the GetShows query again we still receive an empty array—there&#39;s nothing hooked up to the API yet.</p><p>Before fixing that let’s fix another tiny issue.</p><p>The time value can currently be <em>any</em> string, but only <em>valid time strings</em> should be allowed.</p><h4>Making sure time is time</h4><p>In the Shows type, we&#39;ve accepted String as the GraphQL type for the timefield. While this could work for some applications I&#39;d rather have it be a type that actually represents date and time.</p><p>Let’s import GraphQlDateTime from the graphql-iso-date package and add it as the DateTime <em>scalar</em> to the GraphQL API.</p><p><em>I’m not going to explain exactly what a scalar is, just know that if the </em><em>DateTimereceives anything else than a valid ISO time string it&#39;ll throw an error.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/726f6d0fd977563cc51359d587d61542/href">https://medium.com/media/726f6d0fd977563cc51359d587d61542/href</a></iframe><p>Now you’ll receive a GraphQL error if you attempt to pass an invalid time string, like &quot;2017-13-01T12:00:00Z&quot; <em>(the 13th month?)</em>.</p><h3>Let’s return some data</h3><p>We’re done with the GraphQL API for now, but it’d be fun if the allShows()query returns some shows.</p><p>For the time being, let’s return some mock data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34d111a97cda8ab0a1bd45ecf68bcf9d/href">https://medium.com/media/34d111a97cda8ab0a1bd45ecf68bcf9d/href</a></iframe><p>Running GetShows is now a little bit more interesting.</p><h3>Summing it up</h3><p>Although playing with mock data is cool and all, it’s way more interesting if the AddShow command saves the show so the GetShows query can read it. <em>Time for some plumbing...</em></p><p>If you want to you could now hook this GraphQL API up to a frontend app <em>(for example using </em><em>apollo-client)</em>.</p><p>In Part 2 we’ll make the API work by using a <em>re-e-eally</em> simple in-memory storage: an array. We’ll also talk a lot about events and how what we store is, <em>like totally</em>, a simple variant of Event Sourcing.</p><p>Previous: <a href="https://medium.com/@marcusstenbeck/show-calendar-part-0-intro-starter-kit-ad9a07c43f6d">Part 0: Intro &amp; Starter Kit </a><br>Next: <a href="https://medium.com/@marcusstenbeck/part-2-implementing-event-sourcing-for-dummies-ffc11dc3dcc">Part 2: Implementing Event Sourcing (for Dummies!)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89c4b55234df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>