<?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[A Squared Digital - Medium]]></title>
        <description><![CDATA[A full service digital strategy agency. We turn information into experiences people care about. - Medium]]></description>
        <link>https://medium.com/a-squared-digital?source=rss----29dbf7a7ce7f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>A Squared Digital - Medium</title>
            <link>https://medium.com/a-squared-digital?source=rss----29dbf7a7ce7f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 18:46:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/a-squared-digital" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing your GraphQL Endpoint]]></title>
            <link>https://medium.com/a-squared-digital/securing-your-graphql-endpoint-9189886187e4?source=rss----29dbf7a7ce7f---4</link>
            <guid isPermaLink="false">https://medium.com/p/9189886187e4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Daniel Abdelsamed]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 19:29:02 GMT</pubDate>
            <atom:updated>2019-02-25T19:29:50.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CE3lF8FgFjkymbRkg-Dx-Q.png" /></figure><p>GraphQL has been the way of the future when it comes to client-server connections. Its ability to query for the client’s specific needs and mutate data on the spot has almost obliterated my usage of old REST endpoints. The old endpoints provided something that GraphQL doesn’t out of the box: security and consistency. Every time you make a request to a standard REST endpoint, you know exactly the structure of the returned data, along with how computationally expensive the request is going to be.</p><h3>The Problem</h3><p>Let’s take an example from an app my company recently completed. This app allowed our customer’s members to post to the app, along with comment and like the posts. A query for the apps home feed looked something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8697d5ea649b163b8b8b56144f2d69c9/href">https://medium.com/media/8697d5ea649b163b8b8b56144f2d69c9/href</a></iframe><p>This query is not that complicated; with a few optimizations and by using Facebook’s awesome <a href="https://github.com/facebook/dataloader">data loader</a>, we are able to get away with only throwing a handful of simple queries at our database.</p><p>This is all fine and dandy, but if the GraphQL endpoint is open to the public, without restrictions, what stops someone from running a query like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/045b25de590b0abf6b85a1981e7e8105/href">https://medium.com/media/045b25de590b0abf6b85a1981e7e8105/href</a></iframe><p>This is a 100% valid query, but I’m sure you can see that this would wreak havoc on the database. We would have to query for over 10,000,000,000 nodes; no amount of data-loading or query optimization is going to make this easy to run. There is nothing in the way of a malicious user throwing this at your server a few times and bogging down the entire service for everyone else.</p><h3>The Solution</h3><p>So, what can we do about it? Well, there are two types of GraphQL endpoints we need to consider. Public endpoints are designed such that anyone can implement your data in their own application. An example of this would be <a href="https://developer.github.com/v4/">GitHub’s GraphQL API</a>. Internal endpoints are designed for the frontend engineers to use when building an app, and no one else. This is what we have been using at A-Squared Digital, and are probably what most companies have implemented. Each of these methods have their own way of</p><h4>Public Endpoints</h4><p>These are a little tricky, because it requires some analytics on the speed of the different queries within your application. The easiest way to go about blocking complicated queries is to determine a <em>cost</em> for each query. This is determined before the query is executed, and queries over a certain cost cap will be denied.</p><p>To calculate the cost, you can use a plethora of different libraries that exist for this purpose. For us at A-Squared, we use <a href="https://19majkel94.github.io/type-graphql/">type-graphql</a> to dynamically generate our GraphQL document, and it supports on-the-fly query complexity calculation; <a href="https://19majkel94.github.io/type-graphql/docs/complexity.html">here’s the page on that</a>.</p><p>This is a general solution and it will have to be fine tuned based on your server capacity and how much your clients are paying for your endpoint. It is also important to authorize your users so that each request comes with an authorization token. Without that, there would be no way to determine if a specific user is causing trouble, or if your customer base as a whole is using more complicated queries than expected.</p><h4>Internal Endpoints</h4><p>By knowing the entire list of queries that any front-end is going to use, this gives us the ability to completely lock down the endpoint. We know the solution is to generate a list of each query that is going to be used, so how do we go about implementing this?</p><p>Apollo GraphQL, the front-end graphql client we use, has a library called persistgraphql that can help us generate this list. This library creates the ID of the query based on an internal sequential iterator. This means that the first query the script finds will be given the id 1 , the second one 2 and so on. The ApolloNetworkInterface allows the client to replace the query it was going to request with the ID that is generated earlier. The server will then convert that ID back to a query and execute it as normal. The benefit of this is that we can deny any query that is not a specific ID, granting us complete security from arbitrary queries. There is one problem with persistgrapql that required us to create our own branch of the project and use it for development.</p><p>The library only allows the sequential ID system of numbering, and this completely breaks cross version support. If one user is using version 1.0 of an app and we added more components with different queries for version 1.1, we would have to rerun the persistgraphql cli and it would create entirely new IDs that have no correlation to the previously generated set. This means that we would also have to send along the version of the app if we are using the sequential IDs, a non-optimal solution.</p><p>In my <a href="https://github.com/BlenderDude/persistgraphql">fork of the library</a>, I added a few CLI options that allow for cross update consistency. I added a --hash=[type] option; the type could be one of sequential, md5, sha1, uuid. Sequential is what we have seen by the library before and is the default. Using a hash like md5 or sha1 allows us to provide consistency between our updates. A query that has a specific md5 hash in version 1.0, will have the exact same hash in version 1.1, and new/changed queries will have a completely new hash. This allows us to upload our query map to a Redis instance to allow for extremely fast conversions from the hash to a usable query.</p><h3>Conclusion</h3><p>These two methods of securing your endpoint allow you to safely deploy GraphQL without the worry of a query complexity based denial of service attack. Each method is independent of the other, so you could have a service that provides you with customizable simple queries, but more complex ones could require a hash so that they are within your control.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9189886187e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-squared-digital/securing-your-graphql-endpoint-9189886187e4">Securing your GraphQL Endpoint</a> was originally published in <a href="https://medium.com/a-squared-digital">A Squared Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native - Animation With Props]]></title>
            <link>https://medium.com/a-squared-digital/react-native-animation-with-props-78a67adb8db9?source=rss----29dbf7a7ce7f---4</link>
            <guid isPermaLink="false">https://medium.com/p/78a67adb8db9</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Daniel Abdelsamed]]></dc:creator>
            <pubDate>Wed, 30 May 2018 00:50:19 GMT</pubDate>
            <atom:updated>2018-05-30T04:42:57.492Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Native — Animation With Props</h3><p>React Native’s built in Animation library makes creating animated UI elements a breeze. But implementing animations in every component’s stategets tedious and greatly reduces reusability. While in the process of designing an app for a customer, you want to create a button that has two different states: enabled and disabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bFgKyxbIYuHLzkhAd3ulBA.png" /></figure><p>For the seasoned React Native developer, this would be an extremely simple task. In the customLargeButton component, there would need to be a simple ternary statement on the style props such that they match the disabled prop. Something like that might be coded as such:</p><pre><strong>export default class </strong>LargeButton <strong>extends </strong>Component {<br>  render() {<br>    <strong>return </strong>(<br>        &lt;View<br>            style={{<br>              backgroundColor: &quot;#4A90E2&quot;,<br>              opacity: <strong>this</strong>.props.disabled ? 0.3 : 1,<br>              justifyContent: &quot;center&quot;,<br>              alignItems: &quot;center&quot;,<br>              borderRadius: 10,<br>              shadowRadius: <strong>this</strong>.props.disabled ? 0 : 2,<br>              shadowOffset: {<br>                width: 0,<br>                height: <strong>this</strong>.props.disabled ? 0 : 2,<br>              },<br>              shadowOpacity: 0.4,<br>              shadowColor: &quot;#000&quot;,<br>              ...<strong>this</strong>.props.style,<br>            }}<br>        &gt;<br>          &lt;Text<br>              style={{<br>                fontSize: 24,<br>                color: &quot;white&quot;,<br>              }}<br>          &gt;<br>            {<strong>this</strong>.props.text}<br>          &lt;/Text&gt;<br>        &lt;/View&gt;<br>    )<br>  }<br>}</pre><pre>LargeButton.defaultProps = {<br>  text: &quot;Button&quot;,<br>  disabled: <strong>false</strong>,<br>}</pre><p><em>Note: Here I am using </em>View<em> to demonstrate the styling, but in practice you could use </em>TouchableOpacity<em> or wrap the </em>View<em> in a </em>TouchableWithoutFeedback</p><p>Perfect, our job is done! Right? Well, technically this is a working component, but something seems off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*TTfTZwhBqIlO5vI-prKNGA.gif" /></figure><p>Everything happens so…instantly. This may be the desired result in some scenarios, but generally, the end user is going to expect an animation. In the real world, nothing happens instantly, everything takes time. To make an app feel natural, animations are a must.</p><p>To implement animations into our existing component. We need to do a few items:</p><ul><li>Implement an animated value in the state</li><li>Watch the props for updated values</li><li>Create interpolations on the component styles</li></ul><p>To create animations that are based on props, the Animated.Value() initial value needs to be based on what the initial props are. The initiation in statewould look like this.</p><pre>state = {<br>  disabledAnimation: new Animated.Value(this.props.disabled ? 1:0)<br>}</pre><p>Our second task is to watch for change on the animation-triggering props. For us, this prop is disabled . We can utilize the componentWillReceivePropshandler to detect when disabled changes. We want to trigger the animations when disabled changes so we will setup the function like this:</p><pre>componentWillReceiveProps(nextProps){<br>  if(nextProps.disabled !== this.props.disabled){<br>    Animated.timing(this.state.disabledAnimation,{<br>      duration: 300,<br>      toValue: nextProps.disabled ? 1:0 //Same as Animated.Value<br>    }).start()<br>  }<br>}</pre><p>Never forget the .start() at the end of the Animated.timing , it’s even more annoying than a semicolon because it won’t even throw an error, your animation will just not work!</p><p>You might also notice that we have a presumably unnecessary check to see if nextProps.disabled is different than this.props.disabled . Technically we could just always call the Animated.timing function and let that run, but as React Native developers, the key to a smooth app is to cross the native bridge as few times as possible. So if a check can be done in JS, then its worth it.</p><p>Our final task is to link our disabledAnimation variable to the styles of the component. To make our component animatable, we need to change it from a View to an Animated.View . Then we need to utilize .interpolate() on the disabledAnimation variable to tell our view what the styles need to be at either side of the animation. After these modifications, our component will look like this:</p><pre>render() {<br>  <strong>return </strong>(<br>    &lt;Animated.View<br>      style={{<br>        backgroundColor: &quot;#4A90E2&quot;,<br>        opacity: <strong>this</strong>.state.disabledAnimation.interpolate({<br>          inputRange: [0, 1],<br>          outputRange: [1, 0.3],<br>        }),<br>        justifyContent: &quot;center&quot;,<br>        alignItems: &quot;center&quot;,<br>        borderRadius: 10,<br>        shadowRadius: <strong>this</strong>.state.disabledAnimation.interpolate({<br>          inputRange: [0, 1],<br>          outputRange: [2, 0],<br>        }),<br>        shadowOffset: {<br>          width: 0,<br>          height: <strong>this</strong>.state.disabledAnimation.interpolate({<br>            inputRange: [0, 1],<br>            outputRange: [2, 0],<br>          }),<br>        },<br>        shadowOpacity: 0.4,<br>        shadowColor: &quot;#000&quot;,<br>        ...<strong>this</strong>.props.style,<br>      }}<br>    &gt;<br>      &lt;Text<br>        style={{<br>          fontSize: 24,<br>          color: &quot;white&quot;,<br>        }}<br>      &gt;<br>        {<strong>this</strong>.props.text}<br>      &lt;/Text&gt;<br>    &lt;/Animated.View&gt;<br>  )<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*w09EmtVTJhxNGMVaM0qr-Q.gif" /></figure><p>And there we have it! Now our component has beautiful animations based entirely off of a prop value. Now all of the logic for the animations is contained within the component, allowing us to reuse this component anywhere while still keeping the animations!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78a67adb8db9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-squared-digital/react-native-animation-with-props-78a67adb8db9">React Native - Animation With Props</a> was originally published in <a href="https://medium.com/a-squared-digital">A Squared Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>