Git Product home page Git Product logo

android-gql's Introduction

Android lightweight Graphql library

An alternative network library for executing queries or mutations from a GraphQL server in a simple way. Built on top of OkHttp makes this lib is customizable and easy to use.

This lib takes care of every single use-case from GraphQL requests, and the lib is ready to go for getting the data safely. As simple as creating a Gql builder and listen to the response!

Features

  • It uses OkHttp and already supported HTTP/2
  • Coroutine-first, the return value is suspend function
  • Supported for multiple queries or nested-query at the same request

Setup

Add this in your deps

implementation('app.isfaaghyth.graphql:1.0.0')

Don't forget to add the internet permission on AndroidManifest if you haven't yet

<uses-permission android:name="android.permission.INTERNET" />

How-to

Initializing the Lib in onCreate() of Application class

Gql.init("https://gql.isfa.xyz/api")

as it uses OkHttp, you can customize the OkHttpClient while initializing it like this

val okHttpClient = OkHttpClient().newBuilder()
    .addInterceptor(HttpLoggingInterceptor().apply {
        setLevel(HttpLoggingInterceptor.Level.BODY)
    })
    .build()

Gql.init("https://gql.isfa.xyz/api", okHttpClient)

Make your first simple request!

val query = """
    query user_info {
        userInfo {
            id
            name
        }
    }
""".trimIndent()

Gql.query(query)
   .get<UserInfo>(
        onSuccess = {
        },
        onError = {
        }
    )

A request with parameters

val query = """
    query user_info(${'$'}id: String, ${'$'}token: Int, ${'$'}is_active: Boolean) {
        userInfo {
            id
            name
        }
    }
""".trimIndent()

Gql.query(query)
   .parameters(mapOf(
        "id" to "user-123-xyz",
        "token" to 123456789,
        "is_active" to true
    ))
    .get<UserInfo>(
        onSuccess = {
        },
        onError = {
        }
    )

Additionals

Custom header while request

Gql.query(query)
   .headers(mapOf(
        // TODO
    ))

You can also getting the response with another data type:

// T
val response = Gql.query(query).getAsModel<T>()

// String
val response = Gql.query(query).getAsString()

// String with Callback
val response = Gql
        .query(query)
        .get(
            onSuccess = {},
            onError = {}
        )

On-Progress ๐Ÿ‘ท๐Ÿฝโ€

  • .create(GqlServices::java.class) extension for simplified (the design will similar like Retrofit)
  • Supported for a raw file for gql query

@isfaaghyth

android-gql's People

Contributors

isfaaghyth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

noiz354

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.