Skip to content

Instantly share code, notes, and snippets.

View SubhrajyotiSen's full-sized avatar

Subhrajyoti Sen SubhrajyotiSen

View GitHub Profile

Exploring GraphQL on Android

Description

Traditionally most of us have been using REST for our APIs. Even though it has worked well till now, there are multiple pain points around it like too many endpoints, payload bloat, documentation effort etc. Then came GraphQL to save us developers. GraphQL is a query language for APIs.

In this talk, we explore the general pain points regarding REST and understand how GraphQL addresses them. We also go through the process of consuming GraphQL APIs on Android and common things to keep in mind. With Apollo for Android reaching v1.0 recently, now is the perfect time to explore GraphQL on Android.

Elevator pitch

As a mobile developer working with REST APIs, you must have at one point wished that you didn't have to hit different endpoints just for slightly different data. GraphQL was built to address this and many other pain points. Come learn about this new query language and how you can try it on Android.

var amount = 100.0
val installment = 100.0
entryList.add(Entry(0f, 100f)) // initial investment
for (i in 1 until dataPoints.size) {
val diff = (dataPoints[i].price - dataPoints[i - 1].price) / dataPoints[i - 1].price
amount += (amount * diff)
if (i != dataPoints.size - 1)
amount += installment
entryList.add(Entry(i.toFloat(), amount.toFloat()))
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.RecyclerViewHolder> {
private List<BorrowModel> borrowModelList;
private View.OnLongClickListener longClickListener;
public RecyclerViewAdapter(List<BorrowModel> borrowModelList, View.OnLongClickListener longClickListener) {
this.borrowModelList = borrowModelList;
this.longClickListener = longClickListener;
}
<manifest>
<!-- MSM8916 -->
<project name="SubhrajyotiSen/android_device_motorola_harpia" path="device/motorola/harpia" remote="github" revision="cm-14.1" />
<project name="SubhrajyotiSen/android_device_motorola_msm8916-common" path="device/motorola/msm8916-common" remote="github" revision="cm-14.1" />
<project name="SubhrajyotiSen/vendor_motorola" path="vendor/motorola" remote="github" revision="cm-14.1" />
<project name="LineageOS/android_kernel_motorola_msm8916" path="kernel/motorola/msm8916" remote="github" revision="cm-14.1" />
<project name="LineageOS/android_external_bson" path="external/bson" remote="github" revision="cm-14.1" />
<project name="LineageOS/android_device_qcom_common" path="device/qcom/common" remote="github" revision="cm-14.1" />
<manifest>
<project path="device/zuk/z2_plus" name="crdroid-devices/android_device_zuk_z2_plus" remote="github" revision="lineage-15.1"/>
<project path="device/zuk/msm8996-common" name="crdroid-devices/android_device_zuk_msm8996-common" remote="github" revision="lineage-15.1"/>
<project path="vendor/zuk" name="crdroid-devices/android_vendor_zuk" remote="github" revision="lineage-15.1" />
<project path="kernel/zuk/msm8996" name="cosmedd/android_kernel_zuk_msm8996" remote="github" revision="lineage-15.1" />
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n,a) for(int i=a;i<=n;i++)
#define FORN(i,n,a) for(int i=a;i<n;i++)
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
compile "android.arch.lifecycle:extensions:1.0.0"
compile "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
public class MainActivity extends AppCompatActivity implements View.OnLongClickListener {
private BorrowedListViewModel viewModel;
private RecyclerViewAdapter recyclerViewAdapter;
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
import java.util.Date;
@Entity
public class BorrowModel {
@PrimaryKey(autoGenerate = true)
public int id;
private String itemName;
private String personName;
@TypeConverters(DateConverter.class)
private Date borrowDate;
@Database(entities = {BorrowModel.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
public static AppDatabase getDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE =
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "borrow_db")
.build();