<?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 Natalia Majkowska-Stewart on Medium]]></title>
        <description><![CDATA[Stories by Natalia Majkowska-Stewart on Medium]]></description>
        <link>https://medium.com/@natmajkowska?source=rss-cacc3cc6a5fc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AM353dD4fm3XZLqcO4Px9w.png</url>
            <title>Stories by Natalia Majkowska-Stewart on Medium</title>
            <link>https://medium.com/@natmajkowska?source=rss-cacc3cc6a5fc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:11:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@natmajkowska/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[How to add a dark mode splash screen to a React Native app]]></title>
            <link>https://medium.com/brains-beards/how-to-add-a-dark-mode-splash-screen-to-a-react-native-app-f0fb8724d9d7?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0fb8724d9d7</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 09:12:41 GMT</pubDate>
            <atom:updated>2019-10-18T09:12:41.253Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ujBUK7YJmPjlmHeV" /><figcaption>Photo by <a href="https://unsplash.com/@worthyofelegance?utm_source=medium&amp;utm_medium=referral">Alex</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Welcome to the dark side! Dark mode is everywhere after the new iOS 13 update. A lot of developers have started adjusting apps to support a dark theme but a lot of developers are also forgetting to adjust the splash screen. In this tutorial I will show you how to give your app a dark mode splash screen in 10 minutes.</p><p>You can toggle a light or dark splash screen based on your phone’s settings. In Android, you can find the setting here: Settings -&gt; Display -&gt; Dark mode. In iOS: Settings -&gt; Display -&gt; Brightness.</p><h4>iOS Dark Mode Splash Screen</h4><p>Let’s do iOS first. Open your react-native iOS project in Xcode.</p><p>Add your image assets to Images.xcassets and on the right-side options section set the Appearance to Any, Light, Dark. Fill the image gaps as needed. In my example, the smiling face is for light mode, and the sad face is for dark mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9PH3tG7z6Xr88HzK40mQA.png" /></figure><p>In the LaunchScreen.xib, set the background for the view as a System Background Color. You can do the same thing for the image as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZ31-uAPbZMXw1U79NQ0zg.png" /><figcaption>LaunchScreen.xib</figcaption></figure><p>Easy, yes?</p><h4>Android Dark Mode Splash Screen</h4><p>Let’s address Android. Open your project in Android Studio. In my sample Android project I have SplashScreenActivity which basically starts MainActivity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80e96c8a122fdcc6c78a09a1754c8b63/href">https://medium.com/media/80e96c8a122fdcc6c78a09a1754c8b63/href</a></iframe><p>In the AndroidManifest.xml file you need to define SplashScreenActivity in LAUNCHER mode. I also added android:theme=”@style/SplashTheme”. This line is responsible for our splash theme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d73d3e4017f07f4815e0746b45d3efb/href">https://medium.com/media/2d73d3e4017f07f4815e0746b45d3efb/href</a></iframe><p>The next step is to add a directory for values-night. The file structure for res should be similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*9l04dythrpJZfvzZmmcLXQ.png" /><figcaption>Project structure</figcaption></figure><p>In the values-night folder, create a styles.xml file with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a03f42ff069695a5be989de65eb1f74/href">https://medium.com/media/7a03f42ff069695a5be989de65eb1f74/href</a></iframe><p>I added a background to SplashTheme as a drawable with my splash screen layout for dark mode. Do the same for light mode, as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d01768c7d0d92ffa36c75c8238a85a3/href">https://medium.com/media/7d01768c7d0d92ffa36c75c8238a85a3/href</a></iframe><p>Now you need to add two drawables: splash_screen_dark.xml and splash_screen_light.xml, and set the images as needed. Here is my example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2da753eb75f9d1e4f085e8e3f5e7c09e/href">https://medium.com/media/2da753eb75f9d1e4f085e8e3f5e7c09e/href</a></iframe><p>Rebuild the project and that’s it :)</p><p>If you’re using react-native-splash-screen, you can set the theme colors for your launch_screen in MainActivity.java.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9b25ea08679cb511b151436ac07a7e2/href">https://medium.com/media/e9b25ea08679cb511b151436ac07a7e2/href</a></iframe><p>You also need to update styles.xml. Similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e605e293cb6311a4c2225e6e59396d4/href">https://medium.com/media/2e605e293cb6311a4c2225e6e59396d4/href</a></iframe><p>Create a theme.xml file inside the values folder and add the following:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;resources&gt;<br>    &lt;attr name=&quot;textColor&quot; format=&quot;color&quot;/&gt;<br>    &lt;attr name=&quot;colorAccent&quot; format=&quot;color&quot;/&gt;<br>    &lt;attr name=&quot;backgroundColor&quot; format=&quot;color&quot;/&gt;<br>    &lt;attr name=&quot;splashBackgroundColor&quot; format=&quot;color&quot; /&gt;<br>&lt;/resources&gt;</pre><p>After that, you can refer to values:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;RelativeLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:background=&quot;?attr/backgroundColor&quot;<br>    android:gravity=&quot;center&quot;&gt;<br>    &lt;ImageView<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        android:src=&quot;@drawable/logo&quot;<br>    /&gt;<br>&lt;/RelativeLayout&gt;</pre><h3>Summary</h3><p>Adding a splash screen based on a user’s theme settings is super easy for iOS. For Android, like most of the time, it’s a bit more effort to make it work but not that difficult. I hope you enjoy my tutorial and if you like it you can give me a 👏. May the force be with you! 💫</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0fb8724d9d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/how-to-add-a-dark-mode-splash-screen-to-a-react-native-app-f0fb8724d9d7">How to add a dark mode splash screen to a React Native app</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add Camera support to a Flutter app]]></title>
            <link>https://medium.com/brains-beards/how-to-add-camera-support-to-a-flutter-app-c1dfd6b78823?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1dfd6b78823</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 11:26:00 GMT</pubDate>
            <atom:updated>2019-04-18T11:26:00.707Z</atom:updated>
            <content:encoded><![CDATA[<p>I’d say 90% of the apps I’ve developed required a camera feature. It can be anything from capturing pictures, loading image paths from a gallery, to manipulating images. In this tutorial, I’m going to show you how to easily add a camera feature to a Flutter app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*q1KakhF2YatD0LCX4i4pHA.jpeg" /><figcaption><a href="https://www.schillers.com/old-camera-project-rolfix-medium-format-film-camera/">Rolfix medium format film camera</a></figcaption></figure><h4>What Are We Building?</h4><p>We’re going to be extending upon our existing <a href="https://blog.brainsandbeards.com/bottom-navigation-with-a-list-screen-in-flutter-d517dc6f22f1">Beers App</a>. Our aim is to be able to add new beers to our application. It will be important to capture an image of the beer we’re adding. We’ll also add some text inputs to collect the name, country of origin, and the beer’s ABV. To help put this all together, we’re going to create a new AddBeerScreen widget.</p><h4>Basic functionality</h4><p>When I had to figure this out, the first thing I did was search for a camera package in Flutter. I came across the following:</p><p><a href="https://pub.dartlang.org/packages/camera">camera | Flutter Package</a></p><p>As per the documentation, we have to set the minSdkVersion to 21 or higher in android/app/build.gradle for an Android app. For iOS, we need to edit ios/Runner/Info.plist and add the following key / values for camera permissions. For a mobile application to have access to the camera, the user has to grant it permissions.</p><pre>&lt;key&gt;NSCameraUsageDescription&lt;/key&gt;<br>&lt;string&gt;Can I use the camera please?&lt;/string&gt;<br>&lt;key&gt;NSMicrophoneUsageDescription&lt;/key&gt;<br>&lt;string&gt;Can I use the mic please?&lt;/string&gt;</pre><p>Before we get started creating a camera widget, we need to add camera dependencies to pubspec.yaml. Please follow the instructions for the camera package to install it.</p><pre>dependencies:<br> flutter:<br>  sdk: flutter<br> http: 0.12.0+1 <br> camera: ^0.4.2</pre><p>First, I created a camera folder in the screens directory and added a camera.dart. The code in the documentation doesn’t fit my structure perfectly, so you’ll want to modify the implementation slightly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61c864760b5bf826940f3937f697362c/href">https://medium.com/media/61c864760b5bf826940f3937f697362c/href</a></iframe><p>We’ll also update the bottom navigation, instantiating a new instance of the CameraWidget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e27ae1aa4bfa0e03a97299dc8f808be6/href">https://medium.com/media/e27ae1aa4bfa0e03a97299dc8f808be6/href</a></iframe><p>Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*vOL_RB-2pNGBBf05Wmt1Ig.png" /><figcaption>New Beer tab</figcaption></figure><h4>Add Beer Screen</h4><p>Okay, we have a basic version working, but what we want to achieve during this tutorial is much more. Here is the view that we’re going for:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*dOdpsJ1aeVY5duJWwuRQPA.png" /></figure><ol><li>The whole view needs to be in a scrolling widget. We need this for a simple reason — our view has inputs so if we want to scroll down to reach them we need a SingleChildScrollView. This widget lets us build a view, which automatically has a scrolling function. SingleChildScrollView creates a box in which a single widget can be scrolled.</li><li>Camera view with a preview of the captured picture.</li><li>Buttons for switching between front and back camera.</li><li>Inputs for beer name, country name and ABV* and a blue button for submit.</li></ol><blockquote>*<a href="https://en.wikipedia.org/wiki/Alcohol_by_volume"><strong>Alcohol by volume</strong></a> (abbreviated as <strong>ABV</strong>, <strong>abv</strong>, or <strong>alc/vol</strong>) is a standard measure of how much alcohol (<a href="https://en.wikipedia.org/wiki/Ethanol">ethanol</a>) is contained in a given volume of an <a href="https://en.wikipedia.org/wiki/Alcoholic_beverage">alcoholic beverage</a> (expressed as a <a href="https://en.wikipedia.org/wiki/Volume_percent">volume percent</a>).</blockquote><p>The first thing we need to declare are some values:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f94dff9de907d2cbf3286168578ea0cc/href">https://medium.com/media/f94dff9de907d2cbf3286168578ea0cc/href</a></iframe><ul><li>scaffoldKey — key which we need to display errors using scaffoldKey.currentState.showSnackBar.</li><li>cameras — we will keep a reference for available cameras</li><li>controller — to show the camera preview on the screen</li><li>isReady, showCamera, imagePath — variables for keeping state and the image path</li><li>nameController, countryController, abvController — input controllers</li></ul><p>Next, we need to initialise the view’s state. It is very important for us to first check for an available camera. Camera.dart offers an asynchronous method for that. The setupCameras method also initialises CameraController and manages the isReady state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9e377ad16bdfb041e87c959794fa210/href">https://medium.com/media/a9e377ad16bdfb041e87c959794fa210/href</a></iframe><p>When our cameras are initialised, it’s time to add a scrollable layout. I use SingleChildScrollView. I then add a Column widget with the camera preview and image preview. There is also a section for the camera capture button. After that, we have a camera options widget and input’s widget.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a0fcd8ebd90895f78d7bdec60298a99/href">https://medium.com/media/2a0fcd8ebd90895f78d7bdec60298a99/href</a></iframe><p>Let’s start with the cameraPreviewWidget. This method returns an AspectRatio widget, which is responsible for returning the child with a specific aspect ratio. Our child here is a CameraPreview widget.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6021dea4b223dcebcf983800c3b5c39/href">https://medium.com/media/d6021dea4b223dcebcf983800c3b5c39/href</a></iframe><p>If we have a camera, we also need a section to show the picture that was taken. The imagePreviewWidget is responsible for this. Basically, it is just a container with SizedBox for displaying an Image from the imagePath. The image that was taken is always saved to the phone’s memory, so for displaying the image, I use Image.file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66d414099952135fb5f589059cda7684/href">https://medium.com/media/66d414099952135fb5f589059cda7684/href</a></iframe><p>The next widget is simply a Row with an icon. The Icon has an onPressed method. If the camera controller isInitialized, the user can call onTakePictureButtonPressed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d39100268d3dafbeb663ca6bc1f9682/href">https://medium.com/media/6d39100268d3dafbeb663ca6bc1f9682/href</a></iframe><p>The onTakePictureButtonPressed method is asynchronous and is responsible for creating a directory with a specific path. This file path is used for image captures. The image will be saved to the filePath.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb879c8700139e2fe6e8eb6033211aa4/href">https://medium.com/media/eb879c8700139e2fe6e8eb6033211aa4/href</a></iframe><p>Not every picture is perfect, so to give the user an opportunity to edit the picture, I’ve also added a editCaptureControlRowWidaget. After the button is pressed, the camera will become visible again and the user can retake the picture.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/852982f781540e130b14573be706d532/href">https://medium.com/media/852982f781540e130b14573be706d532/href</a></iframe><p>The next section contains two buttons which represent the camera options. A user can choose between the front or back camera. The cameraOptionsWidget returns a Row widget with SizedBoxes containing Radio Icons.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc7bec7c6e8382723caa9eca659ab8d3/href">https://medium.com/media/dc7bec7c6e8382723caa9eca659ab8d3/href</a></iframe><p>The radio button has an onChanged function, where I call the onNewCameraSelected method. This method reinitialised the controller with the current cameraDescription.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8aea9bf649c139c0a6d3df41af024fc/href">https://medium.com/media/a8aea9bf649c139c0a6d3df41af024fc/href</a></iframe><p>And finally, it’s time for the last section. To create a beer in app, we need some inputs where user can type in the information. We use for it a simple column with children that render Padding widgets with TextField widgets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c45a7d0137d4664ee616f5dec3b7ce72/href">https://medium.com/media/c45a7d0137d4664ee616f5dec3b7ce72/href</a></iframe><h4>Summary</h4><p>And here’s the final result! We’re able to switch between the front and rear cameras, take a picture and add some extra information in the input fields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*A1Nhdpir1ib20C6eQVkLMQ.gif" /><figcaption>demo</figcaption></figure><p>After reading this tutorial, I hope this makes it a bit easier implementing a camera feature in your applications. Thankfully, implementing a camera feature in a Flutter app isn’t so difficult, but there are a few differences in building the camera layout compared to other technologies, such as ReactNative. If you like my tutorial, visit our blog and there you’ll find Flutter, React Native, GraphQL and other articles.</p><p>Stay tuned because the next Flutter article is coming… 🐺</p><p><strong>PS</strong>. You can also download <a href="https://gist.github.com/redbluenat/59ec48c82310a4dd3152f4b9be4675fc.js">the full source code</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1dfd6b78823" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/how-to-add-camera-support-to-a-flutter-app-c1dfd6b78823">How to add Camera support to a Flutter app</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bottom Navigation with a List Screen in Flutter]]></title>
            <link>https://medium.com/brains-beards/bottom-navigation-with-a-list-screen-in-flutter-d517dc6f22f1?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d517dc6f22f1</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 12:01:00 GMT</pubDate>
            <atom:updated>2019-02-19T12:01:00.846Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello folks, I’ve come back to you after a few weeks away. While I was away, I had some time to tinker with Flutter. In this quick tutorial, I want to show you how to set up a Flutter app with bottom navigation and a scrolling card list.</p><h4>Creating a Flutter app</h4><p>If this is your first time playing with Flutter, I recommend you prepare your development environment and setup a basic Flutter project first. The following material will help:</p><ul><li><a href="https://docs.flutter.io/">Official Flutter Documentation</a></li><li><a href="https://blog.brainsandbeards.com/creating-your-first-flutter-project-using-webstorm-323b149f86cc">Creating your first Flutter project using WebStorm</a> by Brains &amp; Beards</li></ul><h4>Adding bottom navigation in Flutter</h4><p>Using the <strong>material.dart</strong> package for Flutter, we get a Material Design bottom navigation widget, called bottomNavigationBar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPb42G7OyGVVxP7Aiwydag.png" /></figure><p>Let’s create a widget that uses the bottomNavigationBar widget. In lib/screens, add a folder called home and inside this folder create a file called home_screen.dart. Here is the code that I placed in the file we created. It contains three items in the bottom navigation tab.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0466bd8d0947cb03e670c31f3597472/href">https://medium.com/media/d0466bd8d0947cb03e670c31f3597472/href</a></iframe><p>Let’s briefly explain how this works:</p><p>selectedIndex — keeps value of the current index</p><p>widgetOptions — is an array which contains references for the content per bottom navigation item. At the moment, we have just declared text, which means on every selected item in bottom navigation you will see just text. Later on in this article, I will show you how to create a list that will be displayed when pressing on a particular navigation item.</p><p>In the build method, I declared body with the current selected index from widgetOptions and I also added the most important part, which is the bottomNavigationBar widget. We’ve included three items, which are BottomNavigationBarItem widgets. Each item has an icon and text label. BottomNavigationBar accepts a property onTap. This property defines the callback function for handling a press. In our case, it switches selectedIndex for the value that has been tapped.</p><p>Okay, now copy this code to your file. Don’t forget to edit main.dart, and include the HomePage widget. Compile the project and your bottom navigation is done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e90b3b50bf5ecdab0dcbb7d47db2441/href">https://medium.com/media/7e90b3b50bf5ecdab0dcbb7d47db2441/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*gdt0tVa7_xhQn1GFf2LlKw.png" /><figcaption>Bottom navigation in Flutter app</figcaption></figure><h4>Adding a scrollable list to a Flutter app</h4><p>Okay, so now we have the bottom navigation working, it’s time to add a list. In my application, I want to show a list of beers. I’ve gone ahead and created a simple JSON file to store the data.</p><p>Create an assets folder in the main catalogue and add the file beers.json.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6615b0453c4496e223758c5e042c9fb1/href">https://medium.com/media/6615b0453c4496e223758c5e042c9fb1/href</a></iframe><p>In Flutter apps, an asset (or resource) can be bundled and deployed with your app. To add an asset to a Flutter app, it must be specified in the pubspec.yaml file, located at the root of your project.</p><p>Because our JSON file is a resource, we need to include it in pubspec.yaml. This can be done like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6ad12550740580dad5f2908e6cd951a/href">https://medium.com/media/a6ad12550740580dad5f2908e6cd951a/href</a></iframe><p>Okay, now we need to add the beer list to one of our screens. In screens, create a folder called beer_list and inside create a file called beer_list.dart. To build list we use <a href="https://docs.flutter.io/flutter/widgets/ListView-class.html">ListView widget</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58c09c153c79cda4df5f195ec68715ad/href">https://medium.com/media/58c09c153c79cda4df5f195ec68715ad/href</a></iframe><p><strong>ListView</strong> widget displays beers list. I use few widgets to show data for every list item: <strong>Card</strong>, <strong>Column, Text </strong>and <strong>Image</strong>.</p><p>ListView has two main properties:</p><p>itemBuilder —where we specify what to render.</p><p>itemCount— where we pass the number of elements.</p><p>To load the data from the JSON file, we use DefaultAssetBundle. We then have to decode the data from a JSON format. It’s asynchronous code so to handle it we use the FutureBuilder widget.</p><blockquote>The FutureBuilder widget is essentially a widget that returns another widget based on the result of a Future’s execution. The builder callback defines the strategy for what is rendered based on the information in the snapshot from the asynchronous computation (Future). You can read more about the FutureBuilder API <a href="https://docs.flutter.io/flutter/widgets/FutureBuilder-class.html">here</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc8d90ef094957e6bcbe0048906f083d/href">https://medium.com/media/fc8d90ef094957e6bcbe0048906f083d/href</a></iframe><p>Here you have the entire code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25b19273eb59edcb528367e6ec11001c/href">https://medium.com/media/25b19273eb59edcb528367e6ec11001c/href</a></iframe><p>Okay, now we just need to add a reference to your list in the HomeScreen widget I created in the first part of this tutorial.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a992ef9c9c83aa88b7778dfdafb8cceb/href">https://medium.com/media/a992ef9c9c83aa88b7778dfdafb8cceb/href</a></iframe><p>Rebuild and here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*pqMBkbWNHVsyQyYEEMLBHw.gif" /><figcaption>Flutter list</figcaption></figure><h4>Summary</h4><p>Hopefully by now, you’ve set up a simple Flutter app with bottom navigation and a scrolling list view. To summarise everything, we demonstrated how to handle state with the BottomNavigationBar widget. We provided an example for asynchronously rendering a ListView using the FutureBuilder API. And, you should now be familiar with loading assets into your Flutter app using pubspec.yaml and the DefaultAssetBundle API.</p><p>If you like our tutorials, please check out <a href="https://blog.brainsandbeards.com/">our blog</a>. We’ve just fallen in love with Flutter at Brains and Beards. Stay tuned, our next Flutter tutorial is coming soon 🐺.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d517dc6f22f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/bottom-navigation-with-a-list-screen-in-flutter-d517dc6f22f1">Bottom Navigation with a List Screen in Flutter</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 4 — Implementing authentication and integrating with Apollo Client]]></title>
            <link>https://medium.com/brains-beards/part-4-implementing-authentication-and-integrating-with-apollo-client-fb0ff304206?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb0ff304206</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 12:01:00 GMT</pubDate>
            <atom:updated>2019-01-03T12:01:00.815Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*6UDm_YYAXntV0utOXdrehA.jpeg" /></figure><h4>Part 4 — Implementing authentication and integrating with Apollo Client</h4><p>Thanks for checking-in to part four of my blog series <strong>Getting Started with GraphQL and React Native.</strong> This will be the last post in this series. I’m going to be walking through how you can implement authentication with GraphQL, and integrate the sign-up and login functionality in a React Native application.</p><h4>Server-Side</h4><p>First of all, we need to create a User data model user in datamodel.graphql, the User type has an id, name, password and an array of dogs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3169d06f3bd52b314bf580656d94626b/href">https://medium.com/media/3169d06f3bd52b314bf580656d94626b/href</a></iframe><p>Run the following command to deploy the new schema changes:</p><pre><strong>$</strong> prisma deploy</pre><p>You should see a similar result to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*VXxmWNa-b-N7uK87yTqLrA.png" /></figure><p>When we have User model now we can add a type for represents a user with token, I named it AuthPayload:</p><p>We now need to create an AuthPayload type. This represents the data payload that will be returned upon successfully signing-up or logging-in.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a4e1f7636e226fc48cdc3c885635372/href">https://medium.com/media/5a4e1f7636e226fc48cdc3c885635372/href</a></iframe><blockquote>Remember to run prisma deploy after making a change to datamodel.graphql.</blockquote><p>For authentication, we will use a <a href="https://jwt.io/">JSON Web Token</a>. Add the following NPM libraries:</p><pre><strong>$</strong> yarn add jsonwebtoken bcryptjs</pre><p>Now we need to create the mutations for signing-up and logging-in. I will create a new file for it, because there is quite a lot of code and it is better to keep mutations in a separate file. Add a file called Mutations.js in the src directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2f04958fcb0ad8bca5dd8173a46fc2d/href">https://medium.com/media/f2f04958fcb0ad8bca5dd8173a46fc2d/href</a></iframe><p>The file contains three function: do (created in the <a href="https://blog.brainsandbeards.com/part-2-setting-up-apollo-client-in-a-react-native-app-e766c7e872e2">previous tutorial</a>), login and signUp. The login and sign-up functions are resolvers for handling, you guessed it, logging-in and signing-up mutations. We’re using bcrypt to hash and compare passwords, while the jwt library is used to sign a JWT. Update the index.js file with a reference to Mutations.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77a8ec324cea60c9a1993ec097c964ac/href">https://medium.com/media/77a8ec324cea60c9a1993ec097c964ac/href</a></iframe><blockquote>Please note this tutorial won’t go into detail about checking the JSON Web Token on subsequent requests to the GraphQL Server. Ideally, you’ll want to verify the token and make a decision based on the validity of the token. This can be done using authentication middleware for your GraphQL Server, e.g. <a href="http://www.passportjs.org/docs/username-password">Passport.js</a></blockquote><p>To use your custom mutations, graphql-yoga recommends Heroku, so we’ll go with that. You can find step-by-step instructions on how to do this <a href="https://github.com/prisma/graphql-yoga">here</a>.</p><blockquote>Remember to commit all of your changes because Heroku will deploy everything on the current branch.</blockquote><p>Visit the playground after deploying to Heroku:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhC09l_oObswbn40rcUgcA.png" /><figcaption>Playground available for Heroku</figcaption></figure><p>When you click <strong>Schema</strong> on the right, you should see your custom mutations listed. Okay, next let’s add authentication logic to the React Native application.</p><h4>Client-Side</h4><p>I’ve refactored App.js and created new files called DogsScreen.js and LoginScreen.js. The LoginScreen.js file contains form inputs and handlers for logging-in and signing-up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3cda4a4a06272840e9a41bff04081fd/href">https://medium.com/media/c3cda4a4a06272840e9a41bff04081fd/href</a></iframe><p>The DogsScreen.js file is detailed explained in more detail <a href="https://blog.brainsandbeards.com/part-3-mutating-data-in-a-react-native-app-with-apollo-client-2692a3185b7b">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8963f6b3d741a54a22a17201fd5acd2d/href">https://medium.com/media/8963f6b3d741a54a22a17201fd5acd2d/href</a></iframe><p>And now, the most important part, LoginScreen.js. As you can see, I have a new instance of <strong>ApolloClient</strong> with my Heroku URL. I also added the mutations for signUp and login, which have similar arguments to their server-side equivalents. The rest is very similar to DogsScreen. I’ve added some state to demonstrate a successful sign-up and login.</p><blockquote>If you’re not sure how we’ve set up the mutations, you can refer back to the previous tutorial <a href="https://blog.brainsandbeards.com/part-3-mutating-data-in-a-react-native-app-with-apollo-client-2692a3185b7b">here</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac22a660310e81969babbbeb75f8f3f/href">https://medium.com/media/8ac22a660310e81969babbbeb75f8f3f/href</a></iframe><p>Here is the completed application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*XZrmeS1wkzvU4N5SQcJ1Cw.gif" /></figure><p>Thanks everyone for the journey over this past month. I hope you’ve enjoyed reading the posts as much as I’ve enjoyed writing them. Stay tuned for our next tutorial. We are preparing something very interesting. If you like our tutorials, please check our blog for other stories. Otherwise, if you’re keen on Prisma, GraphQL or React Native, check-out some of these tutorials below:</p><h4>Tutorials for Prisma, GraphQL and React Native</h4><ul><li><a href="https://blog.brainsandbeards.com/part-1-setting-up-a-graphql-server-with-prisma-a93a660fd1d7">Part 1 - Setting up a GraphQL Server with Prisma</a></li><li><a href="https://blog.brainsandbeards.com/part-2-setting-up-apollo-client-in-a-react-native-app-e766c7e872e2">Part 2 - Setting up Apollo Client in a React Native app</a></li><li><a href="https://blog.brainsandbeards.com/part-3-mutating-data-in-a-react-native-app-with-apollo-client-2692a3185b7b">Part 3 — Mutating data in a React Native app with Apollo client</a></li></ul><h4>Source Code</h4><p><a href="https://github.com/brains-and-beards/graphql-server">brains-and-beards/graphql-server</a></p><p><a href="https://github.com/brains-and-beards/react-native-graphql-app">https://github.com/brains-and-beards/react-native-graphql-app</a></p><h4>References</h4><ul><li><a href="https://github.com/prisma/graphql-yoga">prisma/graphql-yoga</a></li><li><a href="https://www.heroku.com/">Cloud Application Platform | Heroku</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb0ff304206" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/part-4-implementing-authentication-and-integrating-with-apollo-client-fb0ff304206">Part 4 — Implementing authentication and integrating with Apollo Client</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 3 — Mutating data in a React Native app with Apollo client]]></title>
            <link>https://medium.com/brains-beards/part-3-mutating-data-in-a-react-native-app-with-apollo-client-2692a3185b7b?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/2692a3185b7b</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[prisma]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Thu, 20 Dec 2018 12:01:00 GMT</pubDate>
            <atom:updated>2018-12-20T12:01:00.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ce9z39AS8Ro9bWMTsCTIaA.jpeg" /></figure><h4>Part 3 — Mutating data in a React Native app with Apollo client</h4><p>Thanks for checking-in to part three of my blog series <strong>Getting Started with GraphQL and React Native.</strong> Now that we have all the configuration out of the way, I’ll walk you through how to create and update data using GraphQL and what’s called a <em>Mutation</em>.</p><h4>Create a form</h4><p>In most apps where you can create and update data, you do so via a form. For the purposes of this example, we’ll create a simple form that will ask the user for a dog name and type.</p><p>Create a simple layout and add some &lt;TextInput&gt; components, similar to the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d54a0ae648efa0841066ad141632d81/href">https://medium.com/media/8d54a0ae648efa0841066ad141632d81/href</a></iframe><h4>Execute a mutation operation</h4><p>Now we need to create a mutation for adding a dog. You don’t need to create anything extra on the server-side. Prisma already offers you mutations to create data based on the types in your GraphQL schema. You can test the mutation by opening the Prisma endpoint in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDdEUlLZgO9Bz_akqnobQw.png" /><figcaption>GraphQL Playground</figcaption></figure><p>In my example, I used the createDog mutation and named the operation addDog. When executing a mutation, more times than not you’ll want to send along some user data. This is done through variables.</p><p>To verify the operation is executed successfully, copy the same mutation from above and click the <em>Play</em> button. If successful, you’ll notice the mutation returns an id. That’s because we’ve specified we want the id of the new dog returned in our mutation.</p><p>Let’s add the addDog mutation to our React Native app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fabaf6ae46ac3227552c638a378e991/href">https://medium.com/media/6fabaf6ae46ac3227552c638a378e991/href</a></iframe><p>Okay, we also need to import Mutation from the react-apollo package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8f852874beb9f44d1ccd1b4366c3af2/href">https://medium.com/media/e8f852874beb9f44d1ccd1b4366c3af2/href</a></iframe><p>To execute a mutation operation in a React Native app, we use the Mutation component. It takes a <em>mutation</em> prop, which is where we’ll assign our <em>addDog</em> mutation. The Mutation component uses the <a href="https://reactjs.org/docs/render-props.html">render prop</a> pattern in React. React will call the render prop function and provide you with a mutate function and an object containing data about the mutation’s result. To use the Mutation component, we wrap our existing layout in it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a8f3b13057f6a312bd2c53adb6dcf3c/href">https://medium.com/media/8a8f3b13057f6a312bd2c53adb6dcf3c/href</a></iframe><p>We want to ensure our list of dogs is updated automatically after each successful mutation. For that to happy we can pass a refetchQueries prop to the Mutation component. It takes an array of objects, where you’d specify the queries you want to re-execute.</p><pre>&lt;Mutation mutation={addDog} refetchQueries={[{ query: dogQuery }]}&gt;</pre><p>Look at the button’s onPress method, we call the addDogMutation with variables, very similar to how it was done in the in the playground.</p><blockquote>It’s very useful to first check your mutations are working correctly in the playground because you can save a lot of time. Especially if you have a bug! Trust me, I know… 😂</blockquote><p>Here is the final result of our app, where we can add a new dog:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VgnsuPuwVQ5tAb9WLRPHFw.gif" /></figure><h4>What’s next</h4><p>I hope this article has encouraged you to learn more about GraphQL <a href="https://graphql.org/learn/queries">mutations</a> and how they work in <a href="https://www.apollographql.com/docs/react/essentials/mutations.html">Apollo Client</a>. But, our adventure with GraphQL, Apollo, and Prisma doesn’t stop here. In the next article, we’ll focus on <strong>Implementing Authentication and integrating it with Apollo Client.</strong> If you like our tutorials, remember to follow us on Medium and check out our next post. 😃</p><h4>Source Code:</h4><p><a href="https://github.com/brains-and-beards/react-native-graphql-app">https://github.com/brains-and-beards/react-native-graphql-app</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2692a3185b7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/part-3-mutating-data-in-a-react-native-app-with-apollo-client-2692a3185b7b">Part 3 — Mutating data in a React Native app with Apollo client</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2 - Setting up Apollo Client in a React Native app]]></title>
            <link>https://medium.com/brains-beards/part-2-setting-up-apollo-client-in-a-react-native-app-e766c7e872e2?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e766c7e872e2</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 11:27:46 GMT</pubDate>
            <atom:updated>2018-12-11T11:27:46.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*FjxC1bTm-_tEGrCsZN0-lQ.jpeg" /></figure><p>Hello folks, I hope you had some fun with GraphQL and Prisma. Now it’s time to integrate Apollo Client into a React Native app. I promise it will be fast and easy. 🚀</p><p>First of all, we need a React Native app. We’ll use react-native init for this tutorial. Create an application by entering the following command into your terminal:</p><pre><strong>$</strong> react-native init RNGraphQL</pre><blockquote>If this is your first React Native app, you may need to install the React Native CLI and configure your development environment. Learn how to do that <a href="https://facebook.github.io/react-native/docs/getting-started.html">here</a>.</blockquote><p>To be sure everything is working, we’ll do a quick test run of the application. Run the following command from your terminal:</p><pre><strong>$</strong> react-native run-ios</pre><p>Once you’ve got everything up-and-running, let’s install the required packages for our GraphQL client:</p><pre><strong>$</strong> yarn add graphql graphql-tag apollo-boost react-apollo</pre><p>Your package.json should look similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caa112d9bf1e5a1ead3066b90c65cdc9/href">https://medium.com/media/caa112d9bf1e5a1ead3066b90c65cdc9/href</a></iframe><ul><li><strong>apollo-boost</strong>— a zero-config way to start using Apollo Client.</li><li><strong>react-apollo</strong> — allows you to fetch data from a GraphQL server and then parse it to build components.</li><li><strong>graphql-tag</strong> — helps parse GraphQL queries.</li></ul><p>Now, we need to configure a &lt;ApolloProvider&gt;<strong> </strong>component<strong>, </strong>which wraps the higher-level component giving every component access to <strong>client</strong>. ApolloClient contains an object, which includes a HTTP link and cache. We need to create a new link and cache using HttpLink and InMemoryCache.</p><ul><li><strong>HttpLink</strong> — responsible for fetching GraphQL results from a GraphQL server.</li><li><strong>InMemoryCache</strong> — cache implementation for Apollo, recommended for data store normalization.</li></ul><p>In App.js, initalize a new instance of ApolloClient and store it in the client variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cba4dbfac6d640f0e69cda1fb90ab6d1/href">https://medium.com/media/cba4dbfac6d640f0e69cda1fb90ab6d1/href</a></iframe><p>Run your application to check everything is configured okay. Now, we want to use our GraphQL Server from the <a href="https://blog.brainsandbeards.com/part-1-setting-up-a-graphql-server-with-prisma-a93a660fd1d7">previous tutorial</a> as the server we’ll be connecting to with the GraphQL Client. We’ll only need the Prisma Cloud endpoint, which you can find in graphql-server/database/prisma.yml, and an auth token. The auth token can generated by running theprisma token command from your server’s root directory. Add the endpoint and token to your ApolloClient object, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dcac4fde6ebcf395682784f448baaed/href">https://medium.com/media/0dcac4fde6ebcf395682784f448baaed/href</a></iframe><p>To check it’s actually working, let’s run a simple GraphQL query. When writing your queries from the client, we use the graphql-tag library. The query below will ask the GraphQL server to return an array of dogs with their name and type fields included.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/403c61ea08582ab54da97bdd807e908c/href">https://medium.com/media/403c61ea08582ab54da97bdd807e908c/href</a></iframe><p>The next step is to create a component, which will be responsible for displaying our queried dogs. We can use the graphql function from the react-apollo library. See below for an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c34427baf03c182d3982491a18c9919/href">https://medium.com/media/9c34427baf03c182d3982491a18c9919/href</a></iframe><p>You’ll notice that we’re first checking if the query is still loading and showing a loading message, if that’s the case.</p><p>Here is the complete App.js with our DogComponent.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb50d6ad3194e172137e903e8cb047c7/href">https://medium.com/media/fb50d6ad3194e172137e903e8cb047c7/href</a></iframe><p>Re-run the application and you should see something similar to the following, presuming you’re displaying some dogs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*Ffjd2n4BQdgqZ66JHZwe7g.gif" /><figcaption>Quick Loading and Result</figcaption></figure><p>I hope everything is working for you, 💪🏻 if not let us know in the comments and I’ll do my best to try and help solve your problems. 🤓 Stay tuned for the next post titled: <strong>Mutating data in a React Native app with Apollo Client 👋🏻 </strong>If you are interested in React Native, we publish tips on our blog every week. Make sure to follow us and check our next post! 🤓</p><h4>Source Code:</h4><p><a href="https://github.com/brains-and-beards/react-native-graphql-app">https://github.com/brains-and-beards/react-native-graphql-app</a></p><h4>References:</h4><ul><li><a href="https://www.apollographql.com/">Apollo GraphQL</a></li><li><a href="https://github.com/apollographql/react-apollo">apollographql/react-apollo</a></li><li><a href="https://github.com/apollographql/apollo-client/tree/master/packages/apollo-boost">apollographql/apollo-client</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e766c7e872e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/part-2-setting-up-apollo-client-in-a-react-native-app-e766c7e872e2">Part 2 - Setting up Apollo Client in a React Native app</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1 - Setting up a GraphQL Server with Prisma]]></title>
            <link>https://medium.com/brains-beards/part-1-setting-up-a-graphql-server-with-prisma-a93a660fd1d7?source=rss-cacc3cc6a5fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/a93a660fd1d7</guid>
            <category><![CDATA[prisma]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Natalia Majkowska-Stewart]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 09:58:55 GMT</pubDate>
            <atom:updated>2018-11-27T09:58:55.427Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Gt28r4Qnx6DhBNto676c5w.jpeg" /></figure><p>In this blog series, I’m going to be focusing on <strong>Getting Started with GraphQL and React Native</strong>. Before we start building anything, if you haven’t used GraphQL before, I recommend some primer material on GraphQL. Head over to the official GraphQL documentation <a href="https://graphql.org/learn">here</a>.</p><h4>Folder Structure</h4><p>Let’s get started by setting up the following directory structure:</p><pre>|-- database<br>   |-- datamodel.graphql<br>   |-- prisma.yml<br>|-- src<br>   |-- index.js</pre><p>In my example, I will be using <a href="https://github.com/prisma/graphql-yoga">graphql-yoga</a> by Prisma to setup the GraphQL server. It’s a full-featured GraphQL Server, which contains all the most important features to help setup your server.</p><p>From the root directory of your project’s workspace, run the following commands in the terminal:</p><pre><strong>$</strong> yarn init -y</pre><pre><strong>$</strong> yarn global add graphql-cli prisma</pre><pre><strong>$</strong> yarn add graphql-yoga prisma prisma-binding</pre><p>Update the scripts in your package.json to the following:</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node src/index.js&quot;<br>}</pre><h4>Type Definitions and Resolvers</h4><blockquote><a href="https://graphql.org/learn">A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type</a></blockquote><p>Let’s create some type definitions and resolvers. In my example, I created a Query type which has one field called dogName that must return a String.</p><p>Paste the following code into your src/index.js file. We’ll do a simple test to validate our GraphQL Server is operational and working correctly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ba25617820a57d9735c0c942c831c0b/href">https://medium.com/media/5ba25617820a57d9735c0c942c831c0b/href</a></iframe><p>Once done, run the following command to start the server:</p><p>yarn start</p><p>For the purposes of this demo, the server should be listening on port <strong>4000</strong>. Once the server has started, navigate to <a href="http://localhost:4000/">http://localhost:4000</a> in your browser. You should be presented with the GraphQL playground.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WiYu6mgyPe_1yyt0hDWLLw.png" /><figcaption>GraphQL Playground at http://localhost:4000</figcaption></figure><p>Let’s test the server by querying our dog’s name. Enter the following query on the left-hand side of the playground:</p><pre>{<br>  dogName<br>}</pre><p>Run the query by pressing the play button. If done correctly, you should see a JSON response with our dog’s name in the payload on the right-hand side.</p><h4>Configuring Prisma</h4><p>Great! Our GraphQL Server is working. Let’s get things set up with Prisma.</p><blockquote>Prisma provides a set of APIs to help you connect your GraphQL API to your database without having to worry about all the CRUD boilerplate.</blockquote><p>Add a Dog type to the datamodel.graphql file you created earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a262eba04c3405ab3abae5525a05b00/href">https://medium.com/media/5a262eba04c3405ab3abae5525a05b00/href</a></iframe><p>Now let’s set up the configuration file for Prisma. Open the prisma.yml file you created earlier and change it to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b478a1d5f18886893d119efab40a80b0/href">https://medium.com/media/b478a1d5f18886893d119efab40a80b0/href</a></iframe><blockquote>To read more about service configuration in Prisma, go <a href="https://www.prisma.io/docs/reference/service-configuration/prisma.yml/yaml-structure-ufeshusai8">here</a>.</blockquote><p>Now that we’ve set up a basic data model and configured our Prisma service, let’s test a deployment. From the root of your project workspace, enter the following commands in your terminal:</p><pre><strong>$</strong> cd database<br><strong>$</strong> prisma deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfaZiVC7bjVVepH38ldQJw.png" /><figcaption>Prisma Deployment</figcaption></figure><p>For the purposes of this example, select Demo server from the deployment options. Your browser should open, taking you to the Prisma website. You will be prompted to set up an account in Prisma and then answer a few questions about your Prisma database in the terminal.</p><blockquote>If you’ve already got an existing Prisma account with an operational server, you can select Use other server</blockquote><p>After completing the setup above, the prisma.yml file will have been updated with the new endpoint URL. Before we can use this endpoint, we need to generate an authorization token. This authorization token will be used to authenticate each request made to the Prisma API. Run the following command from the terminal:</p><pre><strong>$</strong> prisma token</pre><p>In your browser, navigate to the endpoint shown in the prisma.yml file. The GraphQL playground for your server should appear. Copy the generated token into the authorization field via the <strong>HTTP Headers</strong> tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lexHljU7ESRRxUHBGySFTg.png" /><figcaption>Adding an authorization token into the HTTP Headers</figcaption></figure><p>To check if the token is valid, click the <strong>Schema</strong> button on the right. The example GraphQL schema should appear on the right.</p><h4>Mutations</h4><p>If you have everything working, let’s add a dog to our database. To change data in a database via a GraphQL API, we use what’s called a <a href="https://graphql.github.io/learn/queries/#mutations">mutation</a>. Copy the following mutation into the GraphQL playground:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28839b11f5e84cb6d870597ac0a5aa0c/href">https://medium.com/media/28839b11f5e84cb6d870597ac0a5aa0c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TNV-97jn1FPuGN4_Ws0lOA.png" /><figcaption>Mutation Example</figcaption></figure><p>Hit the play button, and if everything works correctly, a Dog object will have been added to the database. Our mutation returns the id of the created Dog, which is shown on the right-side of the GraphQL playground.</p><h4>Queries</h4><p>Let’s verify that our new dog exists in the database by running a query. Copy the following query into the GraphQL playground:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f95eedb0eabb0fc6ca58914d2169995/href">https://medium.com/media/6f95eedb0eabb0fc6ca58914d2169995/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dpp0pT5UJrI-eKzmh6dqTA.png" /></figure><p>An array of dogs will be returned. You should see the dog you just created.</p><h4>Connecting Resolvers to the Prisma API</h4><p>The last step of this tutorial will be connecting our GraphQL resolvers to the Prisma API. We will use the prisma-binding library to do this.</p><blockquote>Resolvers are functions that map to fields in your GraphQL Schema. Resolvers provide instructions for turning a GraphQL operations into data. <a href="https://graphql.org/learn/execution">More info</a>.</blockquote><p>Open the index.js file change it to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a380c7a28d0c771cb02cf0621ee5fbd6/href">https://medium.com/media/a380c7a28d0c771cb02cf0621ee5fbd6/href</a></iframe><p>All we did above was create a Prisma binding instance and attach it to the context of the GraphQL Server. Now it’s time to adjust the resolvers. Update your index.js file to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44d7275dd4935fb18df992efe4d0a978/href">https://medium.com/media/44d7275dd4935fb18df992efe4d0a978/href</a></iframe><p>Our resolver functions will now execute the appropriate binding functions of the Prisma binding instance.</p><p>Before we can test this, we need to create a GraphQL Schema. In the project’s src directory, create a file called schema.graphql. Declare the following types inside:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d572e0263ec95f550e0f3c2ea58b5ad5/href">https://medium.com/media/d572e0263ec95f550e0f3c2ea58b5ad5/href</a></iframe><p>In the index.js file, replace the typeDefs path for the Prisma binding instance with ‘src/schema.graphql’</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/166926803e2c8811961de2f53be89a19/href">https://medium.com/media/166926803e2c8811961de2f53be89a19/href</a></iframe><p>Everything is looking good but we’re missing two last pieces. So before the GraphQL Schema can be generated correctly, we have to create a .graphqlconfig.yml file and add a reference the Prisma database schema. Create a .graphqlconfig.yml file in the root directory of your project’s workspace, and paste the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99545b3d61e731cb8ff8e600b40db388/href">https://medium.com/media/99545b3d61e731cb8ff8e600b40db388/href</a></iframe><p>For the end, edit also database/prisma.yml adding following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23174d2f54f7f53565c65f45dfe93f2c/href">https://medium.com/media/23174d2f54f7f53565c65f45dfe93f2c/href</a></iframe><h4>Deploying to Prisma</h4><p>Run the following to deploy and synchronise all your service definition and data model changes with the remote Prisma service, make sure to run it from the root project:</p><pre><strong>$ </strong>yarn prisma deploy</pre><p>Restart your GraphQL server and navigate to <a href="http://localhost:4000/">http://localhost:4000</a>. Verify that you can execute queries to your GraphQL server, similar to the one shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-B8SBCI4GHfKR_hiHLZ_dw.png" /></figure><h4>Source Code</h4><p><a href="https://github.com/brains-and-beards/graphql-server">https://github.com/brains-and-beards/graphql-server</a></p><h4>References</h4><p><a href="https://github.com/prisma/graphql-yoga">prisma/graphql-yoga</a></p><p><a href="https://graphql.github.io/learn/queries/">https://graphql.github.io/learn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a93a660fd1d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brains-beards/part-1-setting-up-a-graphql-server-with-prisma-a93a660fd1d7">Part 1 - Setting up a GraphQL Server with Prisma</a> was originally published in <a href="https://medium.com/brains-beards">Brains &amp; Beards</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>