<?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 Vasim Mansuri on Medium]]></title>
        <description><![CDATA[Stories by Vasim Mansuri on Medium]]></description>
        <link>https://medium.com/@vasim-mansuri71?source=rss-6d8cdfe55fa5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EGPAM76_xcDHuvEm.jpg</url>
            <title>Stories by Vasim Mansuri on Medium</title>
            <link>https://medium.com/@vasim-mansuri71?source=rss-6d8cdfe55fa5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:25:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vasim-mansuri71/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[Implementing GraphQL in Android: Setup and Configuration (Part-2)]]></title>
            <link>https://vasim-mansuri71.medium.com/implementing-graphql-in-android-setup-and-configuration-part-2-84ba51dcc214?source=rss-6d8cdfe55fa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/84ba51dcc214</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Vasim Mansuri]]></dc:creator>
            <pubDate>Sat, 30 Sep 2023 09:32:15 GMT</pubDate>
            <atom:updated>2023-09-30T09:32:15.252Z</atom:updated>
            <content:encoded><![CDATA[<p>“Implementing GraphQL in Android: Setup and Configuration (Part 2)” continues our exploration of GraphQL integration in Android using the <strong>Apollo Android library</strong>. In this installment, we dive into the crucial setup and configuration steps required to harness the power of GraphQL in your Android applications. This guide will walk you through the process of integrating Apollo Android and preparing your project to communicate seamlessly with GraphQL APIs, making data retrieval and manipulation a seamless experience for Android developers.</p><blockquote>With Apollo Kotlin, executing queries and mutations against a GraphQL server is a breeze. The library automatically returns results as strongly typed Kotlin objects tailored to your specific queries. This eliminates the need to manually parse JSON responses, handle raw Maps, or coerce data types, saving you time and effort. Additionally, you’re relieved from the burden of crafting model types manually, as they are auto-generated from your GraphQL schema definitions, which your UI components utilize.</blockquote><blockquote>One of the key advantages of Apollo Kotlin is its query-specific typing. You can only access data that you explicitly request within your queries. If a field isn’t included in your query, attempting to access the corresponding property on the resulting data structure won’t be possible.</blockquote><blockquote>While Apollo Kotlin is initially geared towards Android development, it’s versatile and adaptable for use in any Java or Kotlin application, including Multiplatform projects. This flexibility makes it an excellent choice for simplifying GraphQL interactions across a wide range of development environments.</blockquote><h4>- Begin the process of setting up GraphQL in Android</h4><p>Let’s initiate the step-by-step process of integrating GraphQL in Android by leveraging the Apollo client library.</p><h3><strong>1. Implement the Plugin</strong></h3><ul><li>app/build.gradle.kts or app/build.gradle</li></ul><pre>plugins {<br>    id(&quot;com.apollographql.apollo3&quot;) version &quot;3.8.2&quot;<br>}</pre><blockquote>The plugin includes a compiler responsible for generating models from your queries during the project build process.</blockquote><h3><strong>2. Setting Up the Apollo Gradle Plugin</strong></h3><ul><li>app/build.gradle.kts or app/build.gradle</li></ul><pre>apollo {<br>    service(&quot;service&quot;) {<br>        packageName.set(&quot;com.androidgraphqlsample&quot;) // Replace with your package name<br>    }<br>}</pre><blockquote>Take note of the ‘service’ block: Apollo Kotlin provides the flexibility to configure multiple services, which can be valuable if you’re dealing with multiple GraphQL endpoints. However, for this tutorial, there’s only one service, and you’re free to choose any name for it (in this example, we’ve named it “service”).</blockquote><h3><strong>3. Add dependencies</strong></h3><ul><li>app/build.gradle.kts or app/build.gradle</li></ul><pre>dependencies {<br>    //......<br>    implementation(&quot;com.apollographql.apollo3:apollo-runtime:3.8.2&quot;)<br>} </pre><p>In Android Studio, you’ll notice a yellow banner. It may suggest a project sync, but hold off on clicking it for now. Apollo Kotlin requires a synced schema to function correctly.</p><h3><strong>4. Incorporate the GraphQL schema</strong></h3><p>Apollo Kotlin relies on having a schema to generate type-safe models and code from your queries. There are several methods available for obtaining a schema.</p><p>In this tutorial, we will utilize the <strong>apolloDownloadSchema</strong> Gradle task, which is automatically generated by our plugin. Thanks to GraphQL&#39;s introspection capabilities, this method is compatible with any GraphQL endpoint that has introspection enabled.</p><p>To proceed, open Android Studio and navigate to the project’s root directory, then execute the following command in the Terminal tab:</p><pre>./gradlew :app:downloadApolloSchema --endpoint=&#39;https://countries.trevorblades.com/graphql&#39; --schema=app/src/main/graphql/schema.graphqls</pre><p>Please note that the path provided to --schema is relative to the root of your project.</p><p>Running this command will download a schema.graphqls file from your specified endpoint and save it to app/src/main/graphql/schema.graphqls.</p><p>You may still see the yellow banner that suggests a project sync might be required for the IDE to function properly. Now, it’s time to click “Sync Now.”</p><p>If everything goes smoothly, Apollo Kotlin is now integrated into your project. You’re now ready to write your first query using this schema.</p><h3><strong>5. Creating Your Initial Query</strong></h3><p>The most common GraphQL <strong>operation</strong> is the query, which requests data from your graph in a structure that conforms to your server’s schema. Open the following Url and Modify query by adding and removing required fields from left side from Studio.</p><p>https://studio.apollographql.com/public/countries/variant/current/explorer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OWGQIbFOBJ9GTGKhN_Oidg.png" /><figcaption>Play with this Studio for add and remove fields</figcaption></figure><p><strong>Integrating the Query into Your Project</strong></p><p>Once you’ve ensured that your query is retrieving the desired data, return to Android Studio.</p><ol><li>Navigate to the src/main/graphql/ folder by right-clicking it. This folder should already contain your schema.graphqls file. Now, select New &gt; File:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FiR0sy8EkaqkNEOTdZzpBA.png" /></figure><p>2. Give the name to file as ‘CountriesList.graphql’ and make sure it’s saved at the same level as your ‘schema.graphqls’ file.</p><p>3. Copy your completed query from the Sandbox Explorer and paste it into the ‘CountriesList.graphql’ file</p><pre>query Query {<br>  countries {<br>    name<br>    code<br>  }<br>}</pre><h4>Generate the model</h4><p>To generate your first model, simply <strong>build your project</strong>. The Apollo Kotlin plugin has already defined a task named <strong>generateApolloSources</strong> for this purpose, and you don’t need to manually run it. It will execute automatically during the project build process.</p><blockquote>Note: Autocomplete functionality won’t be available until you’ve built your project. This is because autocomplete relies on the generated code. Whenever you make changes to your queries, remember to rebuild your project for Android Studio to recognize the modifications</blockquote><h4>Inspecting the Generated Code</h4><p>To examine the generated code, follow these steps:</p><ol><li>From the menu, select Navigate &gt; Class.</li><li>Begin typing ‘Countries.’ Android Studio should suggest opening ‘CountriesListQuery.kt.’</li><li>The file should be located at app/build/generated/source/apollo/service/com/androidgraphqlsample/CountriesListQuery.kt.</li></ol><p>The ‘CountriesListQuery.kt’ file defines a root class called ‘CountriesListQuery,’ which contains several nested classes. If you compare these classes to the JSON data returned in the Sandbox Explorer, you’ll notice that the structure aligns. These classes only include properties for the fields requested in your query.</p><p>For an example, try commenting out the <strong>code</strong> property in ‘CountriesListQuery.graphql,’ save your changes, and then rebuild the project. After the build is complete, the ‘CountriesListQuery’ class will now only include the requested ‘name’ property.</p><p>Uncomment the ‘code’ property and rebuild the project to restore it.</p><p>Now that you’ve explored the generated code, it’s time to execute the query!</p><h3>6. Executing Your Initial Query</h3><p>To execute your initial query, follow these steps:</p><p>Creating an ApolloClient</p><ol><li>Create a new file named ‘Apollo.kt’ at the your desire location</li></ol><p>2. In ‘Apollo.kt,’ instantiate an ApolloClient as follows:”</p><pre>import com.apollographql.apollo3.ApolloClient<br><br>val apolloClient = ApolloClient.Builder()<br>    .serverUrl(&quot;https://countries.trevorblades.com/graphql&quot;)<br>    .build()</pre><blockquote>Note: The ‘apolloClient’ variable is defined at the top level so that it can be reused from other parts of the app later on, which can enhance performance. Reusing the ‘apolloClient’ enables the reuse of the underlying OkHttp instance, along with associated thread pools and connections. In a real-world application, it’s advisable to use a dependency injection framework to share the ApolloClient.</blockquote><h4>Execute the query</h4><p>Make a AnyComposable function and add the following code. Utilize the ‘apolloClient’ and the generated ‘CountriesListQuery’ to execute a new query:</p><pre> @Composable<br>    fun AnyComposable() {<br>        LaunchedEffect(Unit) {<br>            val response = apolloClient.query(CountriesListQuery()).execute()<br>            Log.d(&quot;Countries&quot;, &quot;${response.data}&quot;)<br>        }<br>    }</pre><p>Thanks to Kotlin coroutines, the query will be executed in a background thread, even though the code appears synchronous.</p><blockquote>Note: For the sake of simplicity, we are executing the query within a ‘LaunchedEffect’ block here. In a real app, you may prefer to handle this in a ViewModel and follow a more structured layered architecture.</blockquote><h4>Run your query</h4><p>Hit run. you should see in logcat output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cL0K7klzNPUK-Z7z1riI4A.png" /><figcaption>Printed logs</figcaption></figure><p>This indicates that the request was successfully executed, and you can see data now.</p><p>I hope you’re finding this article informative and enjoyable. If you have a keen interest in learning more about GraphQL, I recommend checking out the next article.</p><p>References</p><p><a href="https://www.apollographql.com/">Streamlining APIs, Databases, &amp; Microservices | Apollo GraphQL</a></p><p><a href="https://graphql.org/">https://graphql.org/</a></p><p>Thanks for Reading, Happy Coding….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84ba51dcc214" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL In Android — Basic]]></title>
            <link>https://vasim-mansuri71.medium.com/graphql-in-android-basic-a26270ff67db?source=rss-6d8cdfe55fa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a26270ff67db</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Vasim Mansuri]]></dc:creator>
            <pubDate>Sat, 30 Sep 2023 09:27:48 GMT</pubDate>
            <atom:updated>2023-09-30T09:31:17.285Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with GraphQL in Android: Basic (Part-1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvEG2Pk5FH3KS456gjKRtA.png" /></figure><h3><strong>1. Why We Need GraphQL?</strong></h3><p>GraphQL addresses several issues that developers encounter with traditional RESTful APIs. Here are the key problems it solves:</p><p>1. <strong>Over-fetching and Under-fetching</strong>: REST APIs often return more data than clients need (over-fetching) or require multiple requests to gather all required data (under-fetching). GraphQL allows clients to request only the specific data they need, eliminating wasted bandwidth and extra requests.</p><p>2. <strong>Versioning Complexity</strong>: When REST API structures change, maintaining backward compatibility or managing multiple versions can be challenging. GraphQL’s strong type system enables gradual changes.</p><p>3. <strong>Numerous Endpoints</strong>: RESTful APIs often necessitate multiple endpoints for different use cases, resulting in endpoint proliferation. GraphQL simplifies this by offering a single endpoint for all queries and mutations.</p><p>4. <strong>Round-Trip Efficiency</strong>: In RESTful architectures, obtaining related data often requires multiple round-trips, introducing latency. GraphQL’s ability to aggregate data from various parts of the schema into a single request reduces round-trips and speeds up data retrieval.</p><h3><strong>2. What is GraphQL?</strong></h3><p>GraphQL is a versatile query language designed for API data retrieval, coupled with a server-side runtime that executes queries based on a customizable type system tailored to your data. Unlike traditional APIs, also positioned between the server and client, GraphQL optimizes data querying for more efficient requests. Its adaptability extends across various client platforms, including Android, iOS, and web applications. GraphQL is not bound to any specific database or storage engine; it relies on your existing code and data.</p><h3>3. GraphQL: Advancing Beyond REST</h3><p>To highlight the significant distinctions between REST and GraphQL concerning data retrieval from an API, let’s explore a straightforward example scenario: <strong>In the context of a blogging application</strong>, imagine an app’s requirement to display post titles authored by a specific user. Simultaneously, the same screen should showcase the names of the user’s three most recent followers. How would these requirements be addressed using REST and GraphQL?</p><blockquote>In the last decade, REST has emerged as the de facto standard for designing web APIs, boasting valuable concepts like stateless servers and organized resource access. However, as client requirements evolved rapidly, REST APIs revealed limitations in their adaptability.</blockquote><blockquote>Enter GraphQL, designed to address the growing demand for greater flexibility and efficiency. GraphQL effectively tackles many of the shortcomings and inefficiencies that developers encounter when working with REST APIs.</blockquote><h4>Data Retrieval: REST vs. GraphQL</h4><p>When working with a REST API, data retrieval often involves accessing multiple endpoints. For instance, in this scenario,</p><ol><li>you might begin by calling the <strong>/users/&lt;id&gt; </strong>endpoint to fetch initial user data.</li><li>Next, you’d likely make a request to the <strong>/users/&lt;id&gt;/posts </strong>endpoint to obtain the user’s posts.</li><li>Finally, the third endpoint, <strong>/users/&lt;id&gt;/followers</strong>, would provide a list of followers for the user.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8C-_H9rXNsXqXNUiW6wZfg.png" /><figcaption>With REST, obtaining the necessary data entails making three separate requests to distinct endpoints. This approach often results in overfetching because these endpoints return surplus information that may not be required. Source — <a href="https://www.howtographql.com/">https://www.howtographql.com/</a></figcaption></figure><p>With GraphQL, on the other hand, you can streamline the process by sending a single query to the GraphQL server, specifying your precise data requirements within that query. In response, the server provides a JSON object tailored to meet those requirements directly.</p><figure><img alt="Using GraphQL, the client can specify exactly the data it needs in a query. Notice that the structure of the server’s response follows precisely the nested structure defined in the query." src="https://cdn-images-1.medium.com/max/1024/1*hbheCx0tCzyFv9wGDGTVjA.png" /><figcaption>By leveraging GraphQL, clients gain the ability to precisely define the data they require within their queries. It’s worth noting that the server’s response mirrors the exact nested structure specified in the query, resulting in a highly tailored and efficient data exchange. Source — <a href="https://www.howtographql.com/">https://www.howtographql.com/</a></figcaption></figure><h3>4. Key Concepts in GraphQL</h3><blockquote>These snippets provide a basic understanding of each GraphQL fundamental concept. Keep in mind that real-world GraphQL implementations can be more complex, but these examples should help you get started.</blockquote><ol><li><strong>Schema:</strong> The schema is the fundamental building block of a GraphQL API. It defines the types of data that can be queried and the relationships between them. The schema serves as a contract between the client and server.</li></ol><ul><li>Define a simple GraphQL schema with a User type</li></ul><pre>type User {<br>  id: ID!<br>  name: String!<br>  email: String!<br>}</pre><p>2. <strong>Queries</strong>: Clients use queries to request specific data. Unlike REST, clients control the shape and depth of the response, reducing over-fetching.</p><ul><li>A basic query to fetch a user’s information:</li></ul><pre>query {<br>  user(id: 123) {<br>    id<br>    name<br>    email<br>  }<br>}</pre><p>3. <strong>Mutations</strong>: Mutations modify data on the server. They can <strong>create</strong>, <strong>update</strong>, or <strong>delete</strong> records, offering powerful data manipulation capabilities.</p><ul><li>Example of a mutation to create a new user:</li></ul><pre>mutation {<br>  createUser(name: &quot;Jack&quot;, email: &quot;jack@example.com&quot;) {<br>    id<br>    name<br>    email<br>  }<br>}</pre><p>4. <strong>Types</strong>: GraphQL supports various types, including scalars (int, string) and custom object types. Types define the structure of data.</p><ul><li>Defining a custom object type in GraphQL:</li></ul><pre>type Post {<br>  id: ID!<br>  title: String!<br>  content: String!<br>}</pre><p>5. <strong>Introspection</strong>: GraphQL is introspective, meaning clients can query the schema to discover available types, queries, and mutations, enabling self-documentation.</p><ul><li>Using introspection to list available types:</li></ul><pre>query {<br>  __schema {<br>    types {<br>      name<br>    }<br>  }<br>}</pre><p>6. <strong>Nested Queries</strong>: Clients can nest queries to retrieve related data in a single request, reducing the need for multiple round-trips.</p><ul><li>A nested query to fetch a user and their posts:</li></ul><pre>query {<br>  user(id: 123) {<br>    id<br>    name<br>    posts {<br>      id<br>      title<br>    }<br>  }<br>}</pre><p>7. <strong>Variables</strong>: Variables allow clients to pass dynamic values to queries and mutations, enhancing query reusability.</p><ul><li>Using variables in a query:</li></ul><pre>query GetUser($userId: ID!) {<br>  user(id: $userId) {<br>    id<br>    name<br>  }<br>}<br> <br>Pass the `userId` variable with a value when executing the query.</pre><p>8. <strong>Directives</strong>: Directives like `<a href="http://twitter.com/include">@include</a>` and `<a href="http://twitter.com/skip">@skip</a>` control the execution of fields based on conditions, offering dynamic query behavior.</p><ul><li>Using the `<a href="http://twitter.com/include">@include</a>` directive to conditionally include a field:</li></ul><pre>query {<br>  user(id: 123) {<br>    id<br>    name<br>    email @include(if: true)<br>  }<br>}</pre><p>9. <strong>Subscriptions</strong>: GraphQL supports real-time updates through subscriptions, enabling clients to receive data when it changes.</p><ul><li>A simple GraphQL subscription to listen for new messages:</li></ul><pre>subscription {<br>  newMessage {<br>    text<br>    sender<br>  }<br>}</pre><ul><li>Subscriptions are typically implemented on the server-side using WebSocket connections.</li></ul><p>I hope you’re finding this article informative and enjoyable. If you have a keen interest in learning more about GraphQL, I recommend checking out the next article.</p><p>Next : <a href="https://medium.com/@vasim-mansuri71/implementing-graphql-in-android-setup-and-configuration-part-2-84ba51dcc214">Implementing GraphQL in Android: Setup and Configuration (Part-2)</a></p><p>Thanks for Reading, Happy Coding….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a26270ff67db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understand Kotlin code by generating in Java Code]]></title>
            <link>https://vasim-mansuri71.medium.com/understand-kotlin-code-by-generating-in-java-code-6cc72eedd61d?source=rss-6d8cdfe55fa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cc72eedd61d</guid>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[bytecode]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Vasim Mansuri]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:54:09 GMT</pubDate>
            <atom:updated>2023-01-28T05:54:09.048Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin is a cross-platform, statically typed, general-purpose high-level programming language. Kotlin is designed to <strong>interoperate fully with Java.</strong></p><p><strong>IntelliJ</strong> and <strong>Android Studio</strong> allow to easily see bytecode and Java equivalent code from Kotlin code by following two steps.</p><ol><li>Execute bytecode (By Inbuilt tool into IDE)</li><li>Decompile bytecode</li></ol><p>Let’s understand each step in details as below</p><p>Step 1:</p><p>Executing bytecode is possible by two ways from IDE which are as below</p><ol><li><strong>Tools -&gt; Kotlin -&gt; Show Kotlin Bytecode.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKHT-rKr2SRbRw9kr9eNAA.png" /><figcaption>Show kotlin bytecode from Tools options</figcaption></figure><p>Or</p><p><strong>2. cmd + shift + A (Mac) / ctrl + shift + A (Windows) and type “Kotlin Bytecode”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxCfjwdpfpD9rTaFWXAqeA.png" /><figcaption>Shortcut to execute Kotlin Bytecode</figcaption></figure><p>After executing bytecode afterwards <strong>Kotlin Bytecode </strong>window will appear as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5G_tPxxkqniVFGaMvoNGZQ.png" /><figcaption>Kotlin ByteCode</figcaption></figure><p>Step 2:</p><p>Click on <strong>Decompile </strong>from kotlin bytecode window<strong> </strong>to see generated Java code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DjO-otCBiKeXLCDsFrxe6Q.png" /><figcaption>Genrated java code from Kotlin bytecode</figcaption></figure><p><strong>Kotlin bytecode</strong> tool helps to understand actual implementation of Kotlin features like Data keyword, Extension function, High-Order function, Inline and many more…</p><p>Thanks for Reading .</p><p>Happy Coding….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cc72eedd61d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>