<?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[Volvo Car Mobility Tech - Medium]]></title>
        <description><![CDATA[Tech blog about the Volvo Car Mobility platform - Medium]]></description>
        <link>https://medium.com/volvo-car-mobility-tech?source=rss----250f42e428d8---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Volvo Car Mobility Tech - Medium</title>
            <link>https://medium.com/volvo-car-mobility-tech?source=rss----250f42e428d8---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 09:49:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/volvo-car-mobility-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lessons learned from starting a growth team]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/lessons-learned-from-starting-a-growth-team-8bfc6ce81fdc?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/8bfc6ce81fdc</guid>
            <dc:creator><![CDATA[Filip Stenbeck]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 07:29:30 GMT</pubDate>
            <atom:updated>2023-04-11T07:29:30.356Z</atom:updated>
            <content:encoded><![CDATA[<p>In a modern product company, learning fast has become the most competitive advantage. However, learning by delivering is expensive. According to <a href="https://www.svpg.com/product-fail/">Marty Cagan</a>, at least half of your ideas are simply not going to work. Other studies, for example made by <a href="https://ai.stanford.edu/~ronnyk/ExPThinkWeek2009Public.pdf">Microsoft</a>, have shown that the success rate is most likely even lower than that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*S5aN2WzptE06stQkAV4dZQ.png" /></figure><p>But what if there is a faster way to gain insights about your product and your customers than building and delivering? What happens when you shift the focus from a build-mindset to a learn-mindset? When you realize that your backlog is just a bunch of untested hypotheses. We wanted to find out: so a year ago we started forming a growth team here at <a href="https://www.volvocars.com/en-se/on-demand">Volvo Car Mobility</a>. We are now fully operational and on a mission to spread experimentation and a data-driven way of working in our organization. In this post I share our learnings from this past year and will hopefully inspire you to start your own growth program at your company. It is going to be a long-ish post but feel free to skip to the end for my key takeaways.</p><h3>Don’t call it a growth team</h3><p>So what is a growth team? It can mean almost anything. For us it means a team that focuses on creating hypotheses and then validates these hypotheses by using experiments and statistically sound methods. In practice this means that we run a lot of A/B tests. The idea is to build as little as possible and always be focusing on what can be learnt from the experiments. Our long term goal is to spread a culture of experimentation across the whole organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IQIHa6zodbj-Jp2Y" /></figure><p>When we started our team last year we named it Team Growth. That is not a good name… It is too generic and it can mean so many different things. Growth and growth hacking are terms that have been floating around the marketing space for years. This has often come to mean activities to attract as many users as possible as fast as possible. Our team is experimenting with the whole product and across all user journeys. We span both activation and retention and see ourself as an experiment program not a marketing growth team. Having this name has caused some confusion. One year later we still haven’t come up with a crisp name and are now going under the name Growth &amp; Experimentation or GX for short. It is not fantastic but at least we have an opportunity to start talking about A/B tests when people are wondering about our name.</p><h3>Start under the radar</h3><p>To successfully launch a program like this in an existing organization, you need to start small. A year ago, a product manager, a retention expert from marketing and I started to lay the grounds for our growth and experimentation program. We did it low key and very much in a <a href="https://en.wikipedia.org/wiki/Skunkworks_project">skunk work</a> kind of way.</p><p>We quickly realized that we wanted to get the tools we needed in place before we created a full blown team. The reasoning was that we understood that once this new team was announced we would need to get started running, quickly showing the rest of the organization that this could be done and was worth the investment.</p><p>The big players like <a href="https://engineering.atspotify.com/2020/10/spotifys-new-experimentation-platform-part-1/">Spotify</a> and <a href="https://medium.com/fact-of-the-day-1/experimentation-at-amazon-51b35490d805">Amazon</a> build their own experimental platforms. We knew from the start that we could not do that. We needed to find something off the shelf.</p><p>We went about this thoroughly, spending almost two months meeting suppliers, testing open source tools, and setting up small- to medium-sized proof of concepts. We ended up with a shortlist of seven suppliers and after the evaluation we chose a platform called <a href="https://www.geteppo.com/">Eppo</a>. We could not be happier with that choice, but more on that later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WTT2xYL6YAltO1st" /></figure><h3>Spreading the gospel</h3><p>Our mission in our team is “To get every team at Volvo Car Mobility experimenting by leading the way”. The way we are doing this is first and foremost by running as many experiments as we can. Our team north star is “Number of experiments run” and our goal is to launch one experiment per week. A very ambitious goal and a goal we still have not met. But we are getting closer. The first quarter 2023 our number was up to 0.58 experiments launched per week and we are getting faster with each experiment we run.</p><p>We have set this north star because we believe that the more experiments we run, the better we get at it which will lead to more impactful learnings.</p><p>We have learnt that a combination of running experiments, facilitating hack weeks to get other teams to start experimenting and just extending a helping hand when other teams have questions is a good recipe for success. The key is to be visible but not overwhelm the organization. We are always running experiments but we don’t want to be at all demos and all company meetings talking about our latest findings. We need to find the right time and place to share learnings and our ways of working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lVXoLA6B75akza6X" /></figure><p>Tools are great and having a compelling vision and mission is crucial but the most important thing when starting a program like this is finding the right people. Being in a growth team is very different from being in a traditional product or feature team. You will need people that are ridiculously curious and that thrives in the high speed, high uncertainty landscape that this kind of team operates in. The most important thing for us is always to scale down what we build, finding the smallest possible thing we can build to prove or disprove a hypothesis. The whole idea with this team is to learn before we build. You will need people that enjoy that kind of challenge.</p><p>You also want people that can act as good ambassadors. You need a crew that loves to help their fellow coworkers without being snobbish about the experiments running outside the growth team. The growth team will always be the experts in creating good experiments but it is key when spreading new ideas to let people figure out things for themselves.</p><p>Ok, so who do you need? In our team we have</p><p><strong>Product Manager<br></strong>The anchor of the team. Someone that can evangelize and be the champion of the program and also help the team organize their work. The Product Manager holds the team together and pairing up with me — the engineering manager — to make sure we are working as one team and in alignment with our vision and mission.</p><p><strong>Growth Lead<br></strong>Experimentation is hard. There are a lot of traps to fall into. Not only around making sure we are doing experiments that have a chance to yield statistical significant results, but also making sure we are creating hypotheses that will be beneficial for the users and for the company and have the best chance for learning opportunities. Our growth lead helps us stay in a growth mindset and leads the day to day work in the team.</p><p><strong>Data Analyst<br></strong>The data analyst’s main responsibility is doing pre- and post-experiment analyses and to package the learnings in a way for them to have the most impact. Our data analyst helps us with this and also has a background in web analytics so he can help lift the company standards in frontend tracking.</p><p><strong>Developers<br></strong>We need developers to build our A/B tests and to make sure we have the tracking we need in place in the product. In the team we have 2 developers who both think it is great fun to jump between frontend and backend stacks. Also all our experiments live in someone else’s code. The developers in the team also have the skill and empathy to understand what it means to operate in other teams’ codebase. And they are both great ambassadors for growth and for a data-driven approach to development in general.</p><p><strong>Designer<br></strong>We need a designer for the same reason we need developers. We need to be able to quickly create designs that look and behave as beautifully and well functioning as the design we have in the rest of the product but that are created at a much higher pace. Not an easy task and something that takes a lot of skill to pull off.</p><p><strong>Service designer<br></strong>We are lucky to also have a service designer (CX) in our team. Her main responsibility is to help us make sure that we are utilizing all the knowledge we already have about our product and customers when we create our hypotheses. We use our user research to help guide us where to experiment and what to validate.</p><p><strong>Marketing automation and retention experts<br></strong>We have two team members with a marketing background and it has been amazing to have them as part of the team. By having experts in communication and in the tooling needed we are able to use everything we already know about acquisition and retention and also leverage the full power of our marketing automation toolchain when we create our experiments.</p><h3>Partners and platform</h3><p>To be able to be successful we realized we would need to hit the ground running. And to do this we decided to leverage the tooling that is already out there and also partner up with people that have deep knowledge in the subject matter. Thanks to <a href="https://www.geteppo.com/">Eppo</a> our experimental platform, we were up and running fast and now Eppo is playing a very important role in our work with scaling the experimentation program.</p><p>Buying an external platform can mean trouble: you have to find a product that matches how you want to work and a supplier whose values match your own. We wanted to take a data warehouse centric approach. We want to control our data, not send data to third party tools. We also think it is crucial to be able to use all our existing customer segmentation and business and operational data in our experiments. Eppo’s platform sits on top of our data warehouse and can therefore act on all data we have (and want to give Eppo access to), making experimentation design and post experiment analysis a breeze. Furthermore, Eppo has proven to be a very important partner, helping us onboard not only in the tool but also has proven to be a good sounding board for us when we built up our program.</p><p>We also decided to partner up with the Stockholm based consultancy firm <a href="https://signific.se/">Signific</a>. Our growth lead is a consultant from Signific and we also had the pleasure to have a Product Manager from Signific for a couple of months to get us started. Having these kinds of experts as part of the journey has been really helpful.Thank you Eppo and Signific, you are awesome.</p><h3>Key learnings</h3><ul><li><strong>Find the right people. </strong>You need people with a curious mind, that like to work fast and are good at finding shortcuts — and most importantly love having their hypotheses being proven wrong.</li><li><strong>Work together</strong>. We have this year been defaulting to do work together. This has enabled us to create better experiments and we have learned a lot from each other. And of course we had loads of fun exploring this new field together as a team.</li><li><strong>Cross functional means marketing included</strong>. Having marketing as part of the team has been absolutely vital for our success.</li><li><strong>Finding the balance </strong>between doing your own experiments and helping other product teams is hard. If too much inward looking the team becomes irrelevant. But too much focus on helping other teams, the team becomes reduced to a support function. If that happens the team loses focus and momentum and cannot be the experts we need them to be. This has maybe been the most difficult part in all of this and we are still trying to find a good balance.</li><li><strong>It will be painfully slow in the beginning</strong>. Your first 10–20 experiments or so will be painful. Maybe you lack frontend analytics in the part you want to experiment on, maybe you even find out you lack the business metrics. People will be nervous when you experiment in their domain and toes will be stepped on. There are a lot of obstacles in the beginning. It is important to see these as necessary bumps in the road and recognize that for each experiment it gets easier.</li><li><strong>Leverage all the help you can get. </strong>Look for competence in your company and don’t forget to look outside product and engineering. And it could be a good idea to also bring in some external experts to get you up and running fast.</li></ul><p>This past year has been so much fun. And it is also very cool seeing a growth mindset spreading through the organization. If you are thinking about starting a program like ours at your company or if you already have started and want someone to share and compare ideas and thoughts with, do not hesitate to reach out to me. I would love to get a knowledge sharing community up and running.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bfc6ce81fdc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/lessons-learned-from-starting-a-growth-team-8bfc6ce81fdc">Lessons learned from starting a growth team</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing federated subgraph with Apollo GraphQL]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/testing-federated-subgraph-with-apollo-graphql-e6e3fb0396dc?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/e6e3fb0396dc</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Alexander Lindquister]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 10:23:06 GMT</pubDate>
            <atom:updated>2023-03-22T07:35:26.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHQBF5jIn8lmt5y_RVba7Q.png" /></figure><p>This is the fifth part in a series of blog posts on the topic of Apollo Federation, and how we use it at Volvo Car Mobility. If you want to read more, make sure to check out our other <a href="https://medium.com/volvo-car-mobility-tech">posts</a>.</p><p>In order to write relevant tests for a subgraph, it helps to understand how the federation gateway makes queries to subgraphs. Make sure to read <a href="https://medium.com/volvo-car-mobility-tech/working-with-entities-in-graphql-federation-a88e9f9865b2">Part 2 (Entities)</a> and <a href="https://medium.com/volvo-car-mobility-tech/subgraph-dependencies-in-apollo-federation-using-requires-and-external-489ef373fb61">Part 4 (Subgraph dependencies)</a>, where we explain the _entities query and how the gateway use it in different situations.</p><h3>Writing tests for a subgraph</h3><p>When writing integration tests for the federated GraphQL endpoints you can either write type-safe tests using generated client classes or write non type-safe tests utilising a string representation of a query.</p><h3>Type-safe testing</h3><p>With io.github.deweyjose:graphqlcodegen-maven-plugin you can enable generating client classes like so: &lt;generateClient&gt;true&lt;/generateClient&gt; (This goes in the maven plugins execution configuration)</p><p>Consider the Car entity from Part 2:</p><pre># Car subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String!<br>}</pre><p>Let’s take a look at how we can write a test for the following query that resolves the fields of Car:</p><pre>query EntitiesQuery($representations: [Any!]!) {<br>  _entities(representations: $representations) {<br>    ... on Car {<br>			id<br>      model<br>    }<br>  }<br>}</pre><p>Note that to test the fields of Car in the car subgraph, we must simulate the queries made by the federation gateway to our specific part of the subgraph, which is handled by our microservice. To accomplish this, we utilise the _entities query. DGS uses the _entities query together with the representations input to resolve queries to a subgraph.</p><p>The following Kotlin code is an example of how we test the above query using <a href="https://netflix.github.io/dgs/generating-code-from-schema/">DGS code generation library</a>:</p><pre>@Test<br>fun `test small Car entity`() {<br>    // Set up<br>    val entitiesQuery = EntitiesGraphQLQuery.Builder().addRepresentationAsVariable(<br>            CarRepresentation().newBuilder().carId(&quot;123&quot;).build()<br>        ).build()</pre><pre>    val request = GraphQLQueryRequest(<br>        entitiesQuery, <br>				EntitiesProjectionRoot()<br>						.onCar()<br>						.carId()<br>						.model()<br>    )</pre><pre>    // Act<br>    val car = dgsQueryExecutor.executeAndExtractJsonPath&lt;Car&gt;(request.serialize(), &quot;data._entities[0]&quot;)</pre><pre>    // Assert<br>    assertThat(car.carId).isEqualTo(&quot;123&quot;)<br>    assertThat(car.model).isEqualTo(&quot;Volvo V60&quot;)<br>}</pre><p>This looks relatively compact, but quickly becomes overwhelming when the request is larger. Let’s say there are a bunch of other fields on the Car entity we want to query in our test:</p><pre>query EntitiesQuery($representations: [Any]) {<br>  _entities(representations: $representations) {<br>    ... on Car {<br>	id<br>        model {<br>	name<br>	description<br>	price {<br>	  hourlyPrice<br>	}<br>	images {<br>	  uri<br>	  size {<br>	    width<br>	    height	<br>	    }<br>          }<br>        }<br>	color {<br>	  name<br>	  hexCode<br>	}<br>	damages {<br>	  type<br>	  images {<br>	    uri<br>	    size {<br>	      width<br>	      height	<br>	    }<br>	}<br>      }<br>    }<br>  }<br>}</pre><p>The corresponding test would look like this:</p><pre>@Test<br>fun `test large Car entity`() {<br>    // Set up<br>    val entitiesQuery = EntitiesGraphQLQuery.Builder().addRepresentationAsVariable(<br>            CarRepresentation().newBuilder().carId(&quot;123&quot;).build()<br>        ).build()</pre><h3>Non type-safe testing</h3><p>In certain situations, we encountered the challenge of overly complex and difficult-to-read code while generating entities projections. To mitigate this issue, we decided to adopt a non-typesafe string definition approach, despite the potential drawbacks of not receiving compilation errors in the tests during schema changes. Our test would hopefully fail in runtime though.</p><p>Another reason is that generating the client libraries can be time-consuming. If we do not need them in the service resolving the subgraph, we can save some build time.</p><p>The above small test then looks as follows:</p><pre>@Test<br>fun `test small Car entity`() {<br>    // Set up<br>    val variables = mapOf(<br>      &quot;representations&quot; to listOf(<br>        mapOf(<br>	  &quot;__typename&quot; to &quot;Car&quot;,<br>	  &quot;carId&quot; to &quot;123&quot;<br>        )<br>      )<br>    )<br>    val request = GraphQLQueryRequest(<br>        entitiesQuery, <br>        EntitiesProjectionRoot()<br>          .onCar()<br>          .carId()<br>          .model()<br>          .name()<br>          .description()<br>          .price()<br>          .hourlyPrice()<br>          .parent()<br>          .images()<br>          .uri()<br>          .size()<br>          .width()<br>          .height()<br>          .parent()<br>          .parent()<br>          .parent()<br>          .color()<br>          .name()<br>          .hexCode()<br>          .parent()<br>          .parent()<br>          .damages()<br>          .type()<br>          .images()<br>          .uri()<br>          .size()<br>          .width()<br>          .height()<br>          .parent()<br>          .parent()<br>        )<br>    // Act<br>    val car = dgsQueryExecutor.executeAndExtractJsonPath&lt;Car&gt;(request.serialize(), &quot;data._entities[0]&quot;)<br>    // Assert<br>    assertThat(car.carId).isEqualTo(&quot;123&quot;)<br>    assertThat(car.model).isEqualTo(&quot;Volvo V60&quot;)<br>  // ...<br>}</pre><p>and the larger example</p><pre>@Test<br>fun `test large Car entity`() {<br>    // Set up<br>    val variables = mapOf(<br>      &quot;representations&quot; to listOf(<br>	mapOf(<br>      	  &quot;__typename&quot; to &quot;Car&quot;,<br>      	  &quot;carId&quot; to &quot;123&quot;<br>	)<br>      )<br>    )<br>    // Act<br>    val car = dgsQueryExecutor.executeAndExtractJsonPath&lt;Car&gt;(<br>      entitiesQuery, <br>      &quot;data._entities[0]&quot;,<br>      variables<br>    )<br>    // Assert<br>    assertThat(car.carId).isEqualTo(&quot;123&quot;)<br>    assertThat(car.model).isEqualTo(&quot;Volvo V60&quot;)<br>  }<br><br>  val entitiesQuery =<br>    &quot;&quot;&quot;<br>    query ($representations: [Any!]!) {<br>       _entities(representations: $representations) {<br>          ... on Car {<br>              id<br>              model {<br>                  name<br>                  description<br>                  price {<br>                      hourlyPrice<br>                  }<br>                  images {<br>                      uri<br>                      size {<br>                          width<br>                          height<br>                      }<br>                  }<br>              }<br>              color {<br>                  name<br>                  hexCode<br>              }<br>              damages {<br>                  type<br>                  images {<br>                      uri<br>                      size {<br>                          width<br>                          height<br>                      }<br>                  }<br>              }<br>          }<br>       }<br>    }<br>    &quot;&quot;&quot;</pre><p>This is definitely more verbose, but some of us prefer it because it’s easier to read and understand.</p><h3>Join the movement</h3><p>This was the last part of our Apollo Federation blog post series. If you have made it this far, great job and thank you! We hope our blog posts have been insightful and useful. If this made you interested in working with Apollo Federation at Volvo Car Mobility, make sure to explore our <a href="https://www.volvocars.com/en-se/on-demand/careers">careers page</a> for open roles.</p><p><a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=testing-federated-subgraph-with-apollo-graphql">Career - Volvo On Demand</a></p><p><em>Written by </em><a href="https://medium.com/u/52e3912b2a35"><em>Iman Radjavi</em></a><em>, </em><a href="https://medium.com/u/117018856328"><em>Christopher Gustafson</em></a><em> and </em><a href="https://medium.com/u/fbd24fa02fcd"><em>Alexander Lindquister</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6e3fb0396dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/testing-federated-subgraph-with-apollo-graphql-e6e3fb0396dc">Testing federated subgraph with Apollo GraphQL</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Subgraph dependencies in Apollo Federation using @requires and @external]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/subgraph-dependencies-in-apollo-federation-using-requires-and-external-489ef373fb61?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/489ef373fb61</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <dc:creator><![CDATA[Christopher Gustafson]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 12:29:35 GMT</pubDate>
            <atom:updated>2024-04-12T08:04:39.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHQBF5jIn8lmt5y_RVba7Q.png" /></figure><p>This is the fourth part in a series of blog posts on the topic of Apollo Federation, and how we use it at Volvo Car Mobility. If you want to read more, make sure to check out <a href="https://medium.com/volvo-car-mobility-tech">our other posts</a> on the topic.</p><p>In this post, the topic will be subgraph dependencies in Apollo Federation. The blog post assumes some basic knowledge of Apollo Federation.</p><h3>When can subgraph dependencies appear?</h3><p>A federated GraphQL setup is a great way to separate the logic and code of individual domains to allow teams to work autonomously and limit the number of teams having to work in the same code repositories. But a world, where each domain and team never have to consider each other, is not realistic. There will always be some dependencies between services and domains.</p><p>Let’s look at an example; the following Car type has a field hourlyPrice that is based on the model of the Car:</p><pre>type Car {<br>  id: ID!<br>  model: String!<br>  hourlyPrice: Int!<br>}</pre><p>But the prices belong to a different domain, which in turn means a different service and subgraph. Using federation, we want the car and price subgraphs to resolve their own fields, the federated schema would look like the following:</p><pre># Car Subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String!<br>}</pre><pre># Price Subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  hourlyPrice: Int!<br>}</pre><p>But hourlyPrice is dependent on model, so there is now a subgraph dependency between the price subgraph and car subgraph. One way to solve it would be to have the car subgraph resolve hourlyPrice by requesting the hourlyPrice of the model from price-service. Alternatively, we could do the other way around, price-service resolves hourlyPrice by sending a request to car-service for the model of a specific id.</p><p>Both alternatives mean we have to create and maintain specific endpoints for resolving other services’ fields. Furthermore, the perk of Federation where a subgraph only needs to care about fields related to its domain is lost. This pattern could quickly become messy and hard to maintain. Luckily Apollo Federation has support for subgraph dependencies using the @requires and @external directives.</p><h3>@external and @requires in Apollo Federation</h3><p>Let’s quickly go over the definitions of the directives from the <a href="https://www.apollographql.com/docs/federation/federated-types/federated-directives/">Apollo Federation documentation</a>:</p><p>@external</p><blockquote>Indicates that this subgraph usually can’t resolve a particular object field, but it still needs to define that field for other purposes.</blockquote><p>@requires</p><blockquote>Indicates that the resolver for a particular entity field depends on the values of other entity fields that are resolved by other subgraphs.</blockquote><p>These two work well together to solve the problem of subgraph dependencies. With these, we can tell the federation gateway that we have a field that requires the value of another field, but we cannot resolve the field ourselves.</p><p>If we want to rewrite the price subgraph schema using these directives it would look like the following:</p><pre># Price Subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String! @external<br>  hourlyPrice: Int! @requries(fields: &quot;model&quot;)<br>}</pre><p>This means that if someone is querying hourlyPrice the gateway have to provide the value of the field model before it can be resolved by the price subgraph. In practice, the federation gateway will first query the Car subgraph for the id and model field, then execute an entities query (for more information about entities see one of our previous blog posts) where the value of model is passed via the representations query variable like this:</p><pre>{<br>  &quot;representations&quot;: [<br>    {<br>      &quot;__typename&quot;: &quot;Car&quot;,<br>      &quot;id&quot;: &quot;1&quot;<br>      &quot;model&quot;: &quot;Volvo V60&quot;<br>    }<br>  ]<br>}</pre><p>The @external field could also be a parent type from which you want to get a value, like in the following example:</p><pre># Price Subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: Model! @external<br>  hourlyPrice: Int! @requries(fields: &quot;model { priceCategory }&quot;)<br>}<br><br>type Model {<br>  name: String<br>  year: Int<br>  priceCategory: String<br>}</pre><p>In this case, we would use the directives in the same manner, and just dig a bit deeper into the representations variable that is passed from the gateway:</p><pre>{<br>  &quot;representations&quot;: [<br>    {<br>      &quot;__typename&quot;: &quot;Car&quot;,<br>      &quot;id&quot;: &quot;1&quot;<br>      &quot;model&quot;: {<br>        &quot;priceCategory&quot;: &quot;C&quot;<br>      }<br>    }<br>  ]<br>}</pre><h3>Implementing a DGS resolver for a field with @requires</h3><p>Let’s take a look at how to implement a resolver for the first hourlyPrice example defined above. We need to extract the value of model from the representations variable to resolve hourlyPrice. In a <a href="https://netflix.github.io/dgs/">DGS</a> resolver, this would look like the following:</p><pre>@DgsComponent<br>class CarResolver(<br>  val priceService: PriceService<br>) {<br>  @DgsEntityFetcher(name = &quot;Car&quot;)<br>  ...<br>  <br>  @DgsData(parentType = &quot;Car&quot;)<br>  fun hourlyPrice(representation: Map&lt;String, Any&gt;): Int {<br>    val model = representation[&quot;model&quot;] as String<br>    return priceService.getHourlyPriceForCarModel(model)<br>  }<br>}</pre><p>We implement the hourlyPrice in the reference resolver of the CarType. By adding an argument of type Map&lt;String, Any&gt; to the function DGS will populate it with the representation of the entity we are currently resolving, that is the element in the $representations list that corresponds to the entity. We extract the value of model from the map and use this to get the price.</p><p>For the second example in the previous section with an object as the external field, we simply parse another Map from the representation passed to the function:</p><pre>@DgsComponent<br>class CarResolver(<br>  val priceService: PriceService<br>) {<br>  @DgsEntityFetcher(name = &quot;Car&quot;)<br>  ...<br><br>  @DgsData(parentType = &quot;Car&quot;)<br>  fun hourlyPrice(representation: Map&lt;String, Any&gt;): Int {<br>    val model = representation[&quot;model&quot;] as Map&lt;String, Any&gt;<br>    val priceCategory = model[&quot;priceCategory&quot;] as String<br>    return priceService.getHourlyPriceForPriceCategory(priceCategory)<br>  }<br>}</pre><h3>Final Words</h3><p>Subgraph dependencies are inevitable in a federated architecture, and it can be easy to default to requests between microservices to solve them. With @requires and @external, you can define your dependencies directly in the schema, and let the Federation gateway handle the additional requests for you. This results in less and more maintainable code, and a better separation of concern, where each subgraph can focus solely on the fields it is responsible for. This is one of the big advantages of working with Apollo Federation.</p><p>If you want to read more about our work with Federation at Volvo Car Mobility, make sure to check out the <a href="https://medium.com/volvo-car-mobility-tech">other blog posts</a> we wrote on the topic.</p><h3>Join the movement</h3><p>If this blog post made you interested in working with Apollo Federation at Volvo Car Mobility, make sure to explore our <a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=subgraph-dependencies-in-apollo-federation-using-requires-and-external">careers page</a> for open roles.</p><p><a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=subgraph-dependencies-in-apollo-federation-using-requires-and-external">Career - Volvo On Demand</a></p><p><em>Written by </em><a href="https://medium.com/u/117018856328"><em>Christopher Gustafson</em></a>, <a href="https://medium.com/u/52e3912b2a35">Iman Radjavi</a> <em>and </em><a href="https://medium.com/u/fbd24fa02fcd"><em>Alexander Lindquister</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=489ef373fb61" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/subgraph-dependencies-in-apollo-federation-using-requires-and-external-489ef373fb61">Subgraph dependencies in Apollo Federation using @requires and @external</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Data Loaders with Apollo Federation]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/using-data-loaders-with-apollo-federation-f21260e3abd1?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/f21260e3abd1</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <dc:creator><![CDATA[Christopher Gustafson]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 08:38:38 GMT</pubDate>
            <atom:updated>2023-03-20T14:54:43.402Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHQBF5jIn8lmt5y_RVba7Q.png" /></figure><p>This is the third part in a series of blog posts on the topic of Apollo Federation, and how we use it at Volvo Car Mobility. If you want to read more, make sure to check out <a href="https://medium.com/volvo-car-mobility-tech">the other posts</a> we wrote about Apollo Federation.</p><p>In this blog post we will be covering Data Loaders and the N+1 problem. We assume you have some basic knowledge of how GraphQL and Apollo Federation works. There will also be some code examples written in Kotlin.</p><h3>The N+1 Problem</h3><p>A common problem when creating GraphQL APIs is the <a href="https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping">N+1 problem</a>. Let’s consider an example. We have one subgraph responsible for resolving information about a car, like its car model, and we have another subgraph responsible for keeping track of stations and what cars are at a certain station:</p><pre># Car subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String!<br>}</pre><pre># Station subgraph<br>type Station {<br>  id: ID!<br>  cars: [Car!]!<br>}</pre><p>A station contains a list of <em>N</em> cars. Say we want to query the model field of each car in the station. This information lives in the car subgraph, which means <em>N</em> queries need to be made to resolve the model of each car. So the result is one query for the list of cars, and <em>N</em> queries for the model of each car. Hence, <em>N+1</em> queries.</p><p>With Federation, the gateway will avoid making <em>N</em> queries to the car subgraph by instead making one batched query for the model of all cars. However, the reference resolver of Car in the car subgraph needs to be modified to properly handle a batched query. If not, the resolver will still be called <em>N</em> times, which in turn might cause N database queries. This can be avoided by using <a href="https://netflix.github.io/dgs/data-loaders/">Data Loaders</a> in DGS.</p><h3>Using a Data Loader</h3><p>When using a DGS data loader, the framework will recognise that many cars need to be loaded, batch up all the calls to the data loader, and call the data loader with a list of cars. Hence, avoiding the <em>N+1</em> problem. The following is an example of a CarDataLoader in the service responsible for the car subgraph:</p><pre>@DgsDataLoader<br>class CarDataLoader(<br>  private val carService: CarService<br>): MappedBatchLoader&lt;String, Car&gt; {<br><br>  override fun load(keys: Set&lt;String&gt;): CompletionStage&lt;Map&lt;String, Car&gt;&gt; = <br>    CompletableFuture.supplyAsync {<br>      carService.getCars(keys.toList()).associateBy { it.id }<br>    }<br>}</pre><p>In the Data Loader, we define the function load() which takes a set of keys and fetches them in batch by calling CarService.getCars().</p><p>We then use the data fetcher in our reference resolver by calling DataLoader.load() with the key we want to load. In the case of a reference resolver, it will be the id of the entity we are resolving which is passed by the federation gateway.</p><pre>@DgsEntityFetcher(name = &quot;Car&quot;)<br>fun car(<br>  map: Map&lt;String, Any&gt;,<br>  dfe: DgsDataFetchingEnvironment<br>): CompletableFuture&lt;Car&gt; {<br>    val carId = map[&quot;id&quot;].toString()<br>    val dataLoader: DataLoader&lt;String, Car&gt; = dfe.getDataLoader(CarDataLoader::class.java)<br>    return dataLoader.load(carId)<br>}</pre><h3>We prefer MappedBatchLoader over BatchLoader</h3><p>We want to highlight one detail in the data loader above, the use of MappedBatchLoader in favour of BatchLoader. Using BatchLoader, our data loader would look like the following:</p><pre>@DgsDataLoader<br>class CarDataLoader(<br>  private val carService: CarService<br>): BatchLoader&lt;String, Car&gt; {<br><br>  override fun load(keys: List&lt;String&gt;): CompletionStage&lt;List&lt;Car&gt;&gt; = <br>    CompletableFuture.supplyAsync {<br>	carService.getCars(keys)<br>    }<br>}</pre><p>In the <a href="https://netflix.github.io/dgs/data-loaders/">DGS data loader documentation</a>, the first example presented uses BatchLoader, which seems to be the default option for data loaders. But a small implementation detail, that can only be found in the source code documentation of BatchLoader , reveals why it is error-prone:</p><blockquote><em>There are a few constraints that must be upheld:</em></blockquote><blockquote><em>- The list of values must be the same size as the list of keys.</em></blockquote><blockquote><em>- Each index in the list of values must </em><strong><em>correspond to the same index</em></strong><em> in the list of keys.</em></blockquote><p>This pitfall can be quite tricky to understand when just reading the online documentation. BatchLoader requires you to know that the order of your values is the same. If you for example rely on a call to a database for fetching your values, the order might not be guaranteed. The possible effects of this are also hard to catch as it doesn’t cause any errors. A list of cars is still returned by the BatchLoader implementation, but when finally loading a single car, you might end up getting the wrong car. This can be devastating!</p><p>If you want to read more about our work with Federation at Volvo Car Mobility, make sure to check out the <a href="https://medium.com/volvo-car-mobility-tech">other blog posts</a> we wrote on the topic.</p><h3>Join the movement</h3><p>If this blog post made you interested in working with Apollo Federation at Volvo Car Mobility, make sure to explore our <a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=using-data-loaders-with-apollo-federation">careers page</a> for open roles.</p><p><a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=using-data-loaders-with-apollo-federation">Career - Volvo On Demand</a></p><p><em>Written by </em><a href="https://medium.com/u/117018856328"><em>Christopher Gustafson</em></a>, <a href="https://medium.com/u/52e3912b2a35"><em>Iman Radjavi</em></a> <em>and </em><a href="https://medium.com/u/fbd24fa02fcd"><em>Alexander Lindquister</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f21260e3abd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/using-data-loaders-with-apollo-federation-f21260e3abd1">Using Data Loaders with Apollo Federation</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with entities in GraphQL Federation]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/working-with-entities-in-graphql-federation-a88e9f9865b2?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/a88e9f9865b2</guid>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <dc:creator><![CDATA[Christopher Gustafson]]></dc:creator>
            <pubDate>Mon, 27 Feb 2023 07:49:27 GMT</pubDate>
            <atom:updated>2023-03-20T14:54:01.016Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHQBF5jIn8lmt5y_RVba7Q.png" /></figure><h3>Working with entities in Apollo Federation</h3><p>This is the second part in a series of blog posts on the topic of Apollo Federation and how we work with it at Volvo Car Mobility. If you are interested, check out the <a href="https://medium.com/@iman.radjavi.vcm/59c647a2ab60">first post</a> where we cover the basics of Federation and why we decided to adopt it.</p><p>In this blog post we will be covering how to work with entities, one of the central concepts of Apollo Federation. We assume you have some basic knowledge of how GraphQL and Apollo Federation works. There will also be some code examples written in Kotlin.</p><h3>What is an Entity in Apollo Federation?</h3><p>An entity is a type which can be resolved from multiple subgraphs. Here is an example of two subgraphs that both can resolve a common type Car. The car subgraph is responsible for resolving Car and all fields id and model:</p><pre># Car subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String!<br>}</pre><p>The reservation subgraph is responsible for resolving the reservations made on a car:</p><pre># Reservation subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  reservations: [Reservation!]!<br>}</pre><p>To the client, the type Car will look like a single type with all of the fields above. But behind the scenes, the <a href="https://www.apollographql.com/docs/federation/building-supergraphs/router">federation gateway</a> will break apart a query for all the fields on Car and send individual queries to the subgraphs that are responsible for the particular fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owwJ3h4Rj1_0zvD6EXw16g.png" /><figcaption>Simplified example of federation gateway breaking apart a client request and querying responsible subgraphs</figcaption></figure><p>All entities have a primary key, which you define directly in the schema using the @key directive, as you see above. This is what the gateway will refer to when combining queries from multiple subgraphs into a single response.</p><h3>Querying an Entity in a subgraph</h3><p>When extending an entity in your subgraph, the gateway needs to be able to query it for fields. Normally, a query in GraphQL is explicitly defined under the Query type in a schema. However, the gateway uses a custom Query._entities query in order to fetch any entity.</p><p>The federation gateway will send a regular GraphQL query to the responsible subgraph that looks like the following when resolving model on the type Car:</p><pre>query EntitiesQuery($representations: [_Any!]!) {<br>  _entities(representations: $representations) {<br>    ... on Car {<br>      model<br>    }<br>  }<br>}</pre><p>Thus, every federated subgraph has to be able to resolve Query._entities . The variable $representations is passed with the _entities query by the gateway. $representations includes the fields needed by the subgraph to resolve the requested entities, in this case it is the typename and id for the type Car as we see below. If the subgraph had multiple entities to resolve (could be both multiple Car types or additional different types) the typename and id would be added to $representations as well.</p><pre>{<br>  &quot;representations&quot;: [<br>    {<br>      &quot;__typename&quot;: &quot;Car&quot;,<br>      &quot;id&quot;: &quot;1&quot;<br>    }<br>  ]<br>}</pre><h3>Reference Resolvers</h3><p>In a subgraph, the _entities query is resolved using <a href="https://www.apollographql.com/docs/federation/entities#2-define-a-reference-resolver">Reference Resolvers</a>. These are responsible for resolving the fields of entities that the subgraph contributes, based on the entity key. A reference resolver using Netflix’s <a href="https://netflix.github.io/dgs/">DGS Framework</a> in Kotlin could look like the following (in DGS, reference resolvers are called <em>Entity Fetchers</em>):</p><pre>@DgsComponent<br>class CarResolver(private val carService: CarService) {<br>  <br>  @DgsEntityFetcher(name = &quot;Car&quot;)<br>  fun car(map: Map&lt;String, Any&gt;): Car {<br>    val carId = map[&quot;id&quot;].toString()<br>    return carService.getCar(carId)<br>  }<br>}</pre><p>Here the DGS framework does most of the work for us. The @DgsEntityFetcher(name= &quot;Car&quot;) annotation tells DGS that if we receive a _entities with __typename=”Car&quot; , execute this function. We then extract the id field, which we finally use to resolve the model of the given car.</p><h3>Referencing an Entity without contributing fields</h3><p>Entities also allow subgraphs to reference entities without contributing any fields. This is useful when a service stores a reference to an entity but no knowledge of its other fields. For example, a service responsible for the station of cars might have a reference to each car, but no other information about the car itself.</p><pre># Station subgraph<br>type Station @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  cars: [Cars!]!<br>}<br><br>type Car @key(fields: &quot;id&quot;, resolvable: false) {<br>  id: ID!<br>}</pre><p>This allows the station service to resolve car entities without any other knowledge about them. What’s also nice is that the station service doesn’t need to add any code for a Car reference resolver, which is specified using resolvable: false. This is an indication to the gateway to avoid resolving any Car fields in this subgraph. The only way Car can be resolved through the station subgraph is thus when resolving a Station. We then only have to implement a reference resolver for Station and avoid implementing it for Car.</p><h3>Implementing reference resolvers</h3><p>Throughout our migration efforts from a monolithic API layer to federated subgraphs, we iterated on a few different ways of implementing reference resolvers. With large complex entities, it was not straightforward how to design reference resolvers that allowed us to separate logic of individual entity fields while avoiding making additional database calls or requests.</p><p>Let’s look at an example of how we chose to implement our reference resolvers. Recall the Car type with one additional field currentStation which returns the station where the car is currently located. Our new type looks like the following:</p><pre># Car subgraph<br>type Car @key(fields: &quot;id&quot;) {<br>  id: ID!<br>  model: String!<br>  currentStation: Station!<br>}<br><br>type Station @key(fields: &quot;id&quot;) {<br>  id: ID!<br>}</pre><p>For this type we define our own internal data type that is used in the resolver. It looks like the following:</p><pre>data class Car(<br>  // Schema fields<br>  val id: UUID,<br>  val model: String,<br>  <br>  // Internally used fields<br>  val currentStationId: UUID<br>)</pre><p>Before diving into details let’s take a look at the reference resolver too:</p><pre>@DgsComponent<br>class CarResolver(<br>  val carService: CarService,<br>  val stationService: StationService<br>) {<br>  <br>  @DgsEntityFetcher(name = &quot;Car&quot;)<br>  fun car(map: Map&lt;String, Any&gt;): Car {<br>    val carId = map[&quot;id&quot;].toString()<br>    return carService.getCar(carId).map {<br>      Car(it.id, it.model, it.currentStationId)<br>    }<br>  }<br>  <br>  @DgsData(parentType = &quot;Car&quot;)<br>  fun currentStation(): Station {<br>    val car = dfe.getSource&lt;Car&gt;()<br>    return stationService.getStation(car.currentStationId)<br>  }<br>}</pre><p>Right, let’s cover how the fields of our GraphQL type will be resolved. The fields id and model (our schema fields in the data class above) are resolved by the car function above. DGS will look at the return type of the @DgsEntityFetcher function and map any fields with the same name to the fields in the schema. Any additional fields are ignored (e.g. currentStationId).</p><p>If a field is not returned by the @DgsEntityFetcher function, DGS will look for a matching @DgsData function to resolve the field, which is how we resolve currentStation in this case. Here is where the power of our custom type comes into play. To find the information for the current station, we need the id of it which is stored together with the car in the database. To avoid having to make an additional database lookup, we inject the partially resolved Car to currentStation() using DataFetchingEnvironment.getSource(). This will give us whatever source we returned in the entity fetcher car(), hence why we added the currentStationId to our internal car type.</p><p>This pattern gives us the possibility of avoiding any extra database calls for the car entity which we are working with. At the same time, if a client would query the car without currentStation, we can avoid making the call for the station completely.</p><h3>Final Words</h3><p>When breaking up our monolith into subgraphs, we found a couple of tricky patterns in our schema that were hard to formulate using subgraphs at first. It can be hard to wrap your head around a GraphQL schema that is stitched together from different sources, but which should still behave the same way towards the client. Understanding how to work with entities ended up being an important step for us towards our new federated architecture.</p><p>If you want to read more about our work with Federation at Volvo Car Mobility, make sure to check out the <a href="https://medium.com/volvo-car-mobility-tech">other blog posts</a> we wrote on the topic.</p><h3>Join the movement</h3><p>If this blog post made you interested in working with Apollo Federation at Volvo Car Mobility, make sure to explore our <a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=working-with-entities-in-graphql-federation">careers page</a> for open roles.</p><p><a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=working-with-entities-in-graphql-federation">Career - Volvo On Demand</a></p><p><em>Written by </em><a href="https://medium.com/u/117018856328"><em>Christopher Gustafson</em></a>, <a href="https://medium.com/u/52e3912b2a35"><em>Iman Radjavi</em></a> <em>and </em><a href="https://medium.com/u/fbd24fa02fcd"><em>Alexander Lindquister</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a88e9f9865b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/working-with-entities-in-graphql-federation-a88e9f9865b2">Working with entities in GraphQL Federation</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Volvo Car Mobility use Apollo Federation]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/why-volvo-car-mobility-use-apollo-federation-59c647a2ab60?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/59c647a2ab60</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <dc:creator><![CDATA[Iman Radjavi]]></dc:creator>
            <pubDate>Thu, 23 Feb 2023 13:52:04 GMT</pubDate>
            <atom:updated>2023-03-20T14:30:54.107Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHQBF5jIn8lmt5y_RVba7Q.png" /></figure><p>At Volvo Car Mobility, we’re building a smarter and more sustainable way for people to have access to a car in cities. We provide a car sharing service named Volvo On Demand with the mission of enabling more people to move — freely, meaningfully and sustainably. Today, we have access to all kinds of services in our back pocket (food, music, banking, and more), but our options for using cars are still largely expensive, unreliable or inconvenient. With the technology that’s at our fingertips, we aim to change that — and we should: cars sit idle on our streets 95% of the time.</p><p><a href="https://www.volvocars.com/en-se/on-demand?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=why-volvo-car-mobility-use-apollo-federation">Volvo On Demand</a></p><h3>Architecture</h3><p>Our car sharing service Volvo On Demand is available as a native iOS and Android application. For internal users, we also provide mobile and web applications for fleet management and operations. We use GraphQL as the query language between our clients and server. In the early days, we implemented a single monolithic service to handle all client operations, but this approach soon became inefficient due to the increasing complexity of the platform and the growing number of developers. In order to improve developer speed and system resilience, we decided to break up our monolith into a microservice architecture.</p><p>The GraphQL API layer remained in the monolith, communicating internally via gRPC with multiple microservices to resolve queries, see Figure 1. This meant all teams still had to work within the monolith for GraphQL schema changes, but with the addition of having to define gRPC service-to-service APIs and implement changes in one or more microservices. Additionally, our uptime was heavily dependent on this monolithic service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNog_5Rmnp1AwJKqf6-dJA.jpeg" /><figcaption>Figure 1: Monolithic approach; One GraphQL server is responsible for resolving all client operations.</figcaption></figure><p>In order to achieve the full benefits of our microservice architecture, we had to distribute the GraphQL schema. Additionally, we wanted to keep a single API for clients in order to preserve one of GraphQL’s main advantages over REST. Apollo Federation helps us achieve all of that.</p><h3>Apollo Federation</h3><p>Apollo Federation is a powerful, open architecture that allows for a single GraphQL API to be composed of multiple, independent services. Each independent service defines its own subgraph. Using a process called composition, all subgraphs are intelligently combined into one supergraph. A gateway serves as the access point for the supergraph, receiving incoming operations and routing them across the subgraphs — see Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQOrhTrwCgIiXptw2D8q1w.jpeg" /><figcaption>Figure 2: Federation approach; One gateway receives client operations, routes them across the subgraphs and returns a complete response to clients.</figcaption></figure><p>Apollo Federation enables us to:</p><ul><li>Keep a single GraphQL API towards clients, while the backend is distributed among independent services.</li><li>Increase developer speed by letting us write less code; GraphQL schema changes can be self-contained within one service.</li><li>Increase resilience; the monolith is no longer a single point of failure.</li><li>Reduce deployment risk that occurs when multiple teams work on the same service.</li><li>Simplify end-to-end testing when all components live in the same service.</li><li>Gradually extract parts of our schema into subgraphs, instead of breaking up the entire schema at once.</li></ul><p>Born out of the frustration and pain of working with our GraphQL tests in the monolith, we started off with an initial hackweek project to experiment with Apollo Federation. After further investigation and experimentation on a smaller scale, we were confident that Apollo Federation would be a good solution for us. The final step was to evaluate how well our most critical operations could be run in production as part of a federated subgraph.</p><h3>Final words</h3><p>Recently, one of the core teams at Volvo Car Mobility finished migrating all of their schema definitions into its own subgraph; a giant step towards becoming independent of the monolithic API layer. By adopting Apollo Federation, the team has been able to achieve all of the advantages mentioned in the previous section. Mostly, our developers enjoy the freedom of working in a single service, independently of other teams; less code to write, faster to ship and fewer risks to take!</p><p>Looking back, we stumbled upon some tricky scenarios when migrating to a federated architecture. We had to change our way of thinking around schema design and how execution flows via the gateway. Stay tuned for the upcoming parts in this series of blog posts, where we share our most important learnings to succeed when working in a federated architecture. In the next part, we will talk about <em>entities</em>, one of the most central concepts of Apollo Federation.</p><h3>Join the movement</h3><p>If this blog post made you interested in working with Apollo Federation at Volvo Car Mobility, make sure to explore our <a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=why-volvo-car-mobility-use-apollo-federation">careers page</a> for open roles.</p><p><a href="https://www.volvocars.com/en-se/on-demand/careers?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=why-volvo-car-mobility-use-apollo-federation">Career - Volvo On Demand</a></p><p><em>Written by </em><a href="https://medium.com/u/52e3912b2a35"><em>Iman Radjavi</em></a><em>, </em><a href="https://medium.com/u/117018856328"><em>Christopher Gustafson</em></a><em> and </em><a href="https://medium.com/u/fbd24fa02fcd"><em>Alexander Lindquister</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59c647a2ab60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/why-volvo-car-mobility-use-apollo-federation-59c647a2ab60">Why Volvo Car Mobility use Apollo Federation</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send non-fatal errors to Firebase Crashlytics with Sensible Logging]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/send-non-fatal-errors-to-firebase-crashlytics-with-sensible-logging-5ac117c6e1be?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/5ac117c6e1be</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Christian]]></dc:creator>
            <pubDate>Thu, 26 Jan 2023 07:50:17 GMT</pubDate>
            <atom:updated>2023-01-26T07:50:17.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63LGwnbNd808P5vSJ1ddmQ.png" /></figure><p>Recording caught exceptions to Firebase is a great way to stay on-top of your app’s health as it’s running in production. Especially when paired up with notifications about spiking or new issues. Read more about them in the Firebase <a href="https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts">documentation</a></p><p>Let’s look at how you can report non-fatal errors using Sensible Logging.</p><p><a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android">GitHub - VolvoCarsMobility/sensible-logging-for-android: Extendable log utils for Android projects</a></p><p>First, we create a <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android#channels">Channel</a> implementation. Channels is how you hook up Sensible Logging to the different sinks you want your log statements to end up in.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d239c9188aee9b11db0dfce0d02117d4/href">https://medium.com/media/d239c9188aee9b11db0dfce0d02117d4/href</a></iframe><p>Here, we simply call Crashlytics’s log() method for everything we receive to our print() method and if there is an exception in the log-line, we log that using recordException() as well.</p><p>We choose to use a <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android/blob/main/README.md#channels">ReleaseChannel</a> since the code is meant to be used in release builds.</p><p>It’s also worth noting that if there’s no exception attached to the log message, there will be no resulting entry in Firebase console. But when an exception do get logged, the previously logged messages will be included.</p><h3>About that Filter 🧐</h3><p>In its current form, the filter will only allow error messages through.</p><p>Let’s fix that.</p><p>We can use the infix or function to combine our level filter together with a Category filter that allows a few select categories through.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/929eea99c77a8cdaf99b5fabcb648a73/href">https://medium.com/media/929eea99c77a8cdaf99b5fabcb648a73/href</a></iframe><p>This should allow us some more context while viewing the non-fatal in Firebase</p><h3>Default versus non-default Channels</h3><p>We’ve set our channels default parameter to true. Meaning that our print method will receive every log statement that passes the filter.</p><p>An option to allow a bit more fine grained control over what gets sent to Crashlytics is to set the default parameter to false. Then we have to pass the Channel ID everytime we want to send something to Firebase.</p><p>Log.e(“Something terrible happened”, exception, Channels.Crashlytics)</p><p>Typically, you combine this option with the AllowAll filter since the two concepts makes a complex mix.</p><h3>Configuring based on build-type</h3><p>Now, let’s configure Sensible Logging to pick up our newly created channel in release build. But in debug builds we keep using the LogCat channel. Here, I’ve modified the setup code from the <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android#usage">Usage</a> section of the README.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2dd589e8b01988a30bbcaf68d3a27b6/href">https://medium.com/media/d2dd589e8b01988a30bbcaf68d3a27b6/href</a></iframe><h3>Wrapping up</h3><p>That’s it for this post. Hopefully I have been able to convey how you can use Sensible Logging to ease logging to Firebase Crashlytics in your project.</p><p>Be sure to check out my previous post about <a href="https://medium.com/@Krillsson/per-developer-log-output-with-sensible-logging-50d8c3b805c7">Per developer log output with Sensible Logging</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac117c6e1be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/send-non-fatal-errors-to-firebase-crashlytics-with-sensible-logging-5ac117c6e1be">Send non-fatal errors to Firebase Crashlytics with Sensible Logging</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Per developer log output with Sensible Logging]]></title>
            <link>https://medium.com/volvo-car-mobility-tech/per-developer-log-output-with-sensible-logging-50d8c3b805c7?source=rss----250f42e428d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/50d8c3b805c7</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Christian]]></dc:creator>
            <pubDate>Mon, 09 Jan 2023 07:41:26 GMT</pubDate>
            <atom:updated>2023-01-09T07:41:26.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63LGwnbNd808P5vSJ1ddmQ.png" /></figure><p>Working on an app with many features and asynchronous code can be tricky. With a good strategy for logging, we can more easily understand the flow of data and behavior of our system.</p><p>But opinions differ when you ask questions such as;</p><p>“<em>Should we log happy paths or just exceptional cases?</em>” <br>And “<em>how much logging should we leave on per default?</em>”</p><p>What if we could support both.</p><p><a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android">GitHub - VolvoCarsMobility/sensible-logging-for-android: Extendable log utils for Android projects</a></p><h3>Categories</h3><p>By dividing our statements into high level areas of interest, managing this becomes so much easier.</p><p>In Sensible Logging, categories are <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android/blob/main/sensible-logging/src/main/java/sh/vcm/sensiblelogging/Category.kt">first-class citizens</a>. As an example, when working on push notifications we can log these using the following statement:</p><pre>Log.d(&quot;Push message received $message&quot;, Categories.Push)</pre><h4>Category filter</h4><p>Lets say Developer <strong>A</strong> is working on Push Notifications and Developer <strong>B</strong> is working on the Registration feature. How do we avoid cluttering Developer <strong>B</strong>’s LogCat with irrelevant messages about Push Notifications?</p><p>That’s when you introduce a <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android/tree/main/sensible-logging/src/main/java/sh/vcm/sensiblelogging/filter">Filter</a>.</p><p>Typically, you setup your filter in the code, or enable them to be toggled in runtime using a <a href="https://github.com/VolvoCarsMobility/sensible-logging-for-android/blob/main/sensible-logging/src/main/java/sh/vcm/sensiblelogging/filter/SharedPreferencesCategoryFilter.kt">SharedPreferencesCategoryFilter</a>.</p><p>But to persist Developer <strong>A</strong> &amp; <strong>B</strong>’s different preferences, let’s create a new category filter that picks up the log categories from their environments instead.</p><p>Let’s look at how we can inject the developers specific preferences from their environments.</p><h3>Gradle</h3><p>We start off by putting our log categories in the app’s <em>build.gradle</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9219833672040c9340d3bab4d4b204c6/href">https://medium.com/media/9219833672040c9340d3bab4d4b204c6/href</a></iframe><p>The above gradle code will result in an entry in the <a href="https://developer.android.com/studio/build/gradle-tips#share-custom-fields-and-resource-values-with-your-app-code">BuildConfig.java</a> that populates a Java string array using the <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html#jls-10.6">quick initialization syntax</a>. Where exactly you put it depends on your configuration, either add it to the <em>defaultConfig {}</em>, <em>debug {}</em>, or &lt;<em>flavour&gt; {}.</em></p><h4>BuildConfigCategoryFilter.kt</h4><p>Now let’s pick this up from our custom Filter using the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bae3af4a4411d1d9393681b3c8b21583/href">https://medium.com/media/bae3af4a4411d1d9393681b3c8b21583/href</a></iframe><p>Then we can modify our logging setup code to use the newly created filter, instead of the default</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/242d17612a8abf0abe7c34c1c64d4530/href">https://medium.com/media/242d17612a8abf0abe7c34c1c64d4530/href</a></iframe><h4>Environment input</h4><p>The last missing piece is to inject our developer environment specific categories according to their individual preferences. There are many ways to achieve this.</p><p>For instance “Android Studio” -&gt; “Preferences” -&gt; “Build, Execution, Deployment” -&gt; “Compiler” has an option to pass “Command-line options”.</p><p>But we are going to use the <em>local.properties</em> gradle properties file to achieve it. This file should have already been added to your .gitignore file if you created the project in Android Studio</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*TTD74RItYl7oQmU4FNRwbg.png" /></figure><p>Let’s add a new entry in our properties file with the following value. To the properties file format, everything after the = sign is just a string. But here we are using the same Java array quick initialization syntax as above. To avoid parsing anything from Gradle.</p><pre>log.categories={&quot;Default&quot;, &quot;Analytics&quot;, &quot;Network&quot;, &quot;Push&quot;}</pre><h4>Gradle configuration</h4><p>Let’s define a utility method to safely read the properties file first.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8de02d9620b1d36d1fc18e2d15cbff32/href">https://medium.com/media/8de02d9620b1d36d1fc18e2d15cbff32/href</a></iframe><p>And now we can use that method to read the properties from the <em>buildConfigField</em> we previously created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/707d726bf21ac2a3ed832b5f24e2c49b/href">https://medium.com/media/707d726bf21ac2a3ed832b5f24e2c49b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f09Ej0hEcVDr0sH2nbj0iA.png" /></figure><p>And then we can reap the benefits of having developer specific log output!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50d8c3b805c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/volvo-car-mobility-tech/per-developer-log-output-with-sensible-logging-50d8c3b805c7">Per developer log output with Sensible Logging</a> was originally published in <a href="https://medium.com/volvo-car-mobility-tech">Volvo Car Mobility Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>