All Projects → florent37 → Android Okgraphql

florent37 / Android Okgraphql

Licence: apache-2.0
Reactive GraphQl client for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Android Okgraphql

Binder
An Annotation processor that allows binding two classes with each other, where the first class can listen to the updates of the second class ... ideal for MVVM and similar patterns
Stars: ✭ 21 (-67.19%)
Mutual labels:  reactive, rxjava, rx
Javawebsocketclient
RxJava WebSocket library for Java and Android
Stars: ✭ 188 (+193.75%)
Mutual labels:  rxjava, reactive, okhttp
Villus
🏎 A tiny and fast GraphQL client for Vue.js
Stars: ✭ 378 (+490.63%)
Mutual labels:  api, graphql, graphql-client
Nohttprxutils
🐠 本库是一款Android-Http标准协议网络通讯框架,基于RxJava+NoHttp封装。支持文件上传和断点续传、文件下载和断点下载、Http协议和Https协议队列网络请求、网络请求轮询。
Stars: ✭ 214 (+234.38%)
Mutual labels:  rxjava, rx, okhttp
Rxkprefs
🛠 A small Kotlin library to make shared preferences easy + RxJava and Coroutines support
Stars: ✭ 264 (+312.5%)
Mutual labels:  rxjava, reactive, rx
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (+379.69%)
Mutual labels:  rxjava, reactive, rx
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (+668.75%)
Mutual labels:  api, rxjava, rx
Graphql Kotlin
Libraries for running GraphQL in Kotlin
Stars: ✭ 1,030 (+1509.38%)
Mutual labels:  graphql, graphql-client
Graphql Retrofit Converter
A Retrofit 2 Converter.Factory for GraphQL.
Stars: ✭ 46 (-28.12%)
Mutual labels:  graphql, rxjava
Best Of Web Python
🏆 A ranked list of awesome python libraries for web development. Updated weekly.
Stars: ✭ 1,118 (+1646.88%)
Mutual labels:  api, graphql
Apollo Angular
A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
Stars: ✭ 1,058 (+1553.13%)
Mutual labels:  graphql, graphql-client
Omdb Graphql Wrapper
🚀 GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-29.69%)
Mutual labels:  api, graphql
Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (-29.69%)
Mutual labels:  graphql, graphql-client
Graphql Query Test Mock
Easily mock GraphQL queries in your Relay Modern / Apollo / any-other-GraphQL-client tests.
Stars: ✭ 49 (-23.44%)
Mutual labels:  graphql, graphql-client
Realm Graphql Service
GraphQL service for Realm Object Server
Stars: ✭ 44 (-31.25%)
Mutual labels:  graphql, reactive
Graphql Inspector
🕵️‍♀️ Validate schema, get schema change notifications, validate operations, find breaking changes, look for similar types, schema coverage
Stars: ✭ 1,059 (+1554.69%)
Mutual labels:  api, graphql
Weaponapp
一个尽量做到极致的集大成App,努力做到最好(开发阶段)——MVVM+Retrofit+RxJava+Small 插件化+单元测试+MD
Stars: ✭ 1,011 (+1479.69%)
Mutual labels:  rxjava, okhttp
Meteorite
一个基于Android MVP的简单明了的指引性通用架构,目的是帮助更多的开发者去全面了解实践开发相关的各种技术,快速搭建属于自已的APP。这个项目涉及到如下技术的实际应用:1、MVP 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)3、DbFlow(可保存文件入SD卡) 4、6.0权限申请 5、XRecyclerView 6、万能Adapter7、异常处理 8、日志打印 9、屏幕适配 10、代码混淆 11、多渠道打包 12、内存泄露检测 13、热修复 14、升级更新 15、极光推送 工程更新完善中……欢迎关注 @特别感谢ZJ.Y的Logo支持。
Stars: ✭ 49 (-23.44%)
Mutual labels:  rxjava, okhttp
Audio player flutter
🎧 Apple Music / Tidal Audio Player for Flutter
Stars: ✭ 52 (-18.75%)
Mutual labels:  reactive, rx
Rxplaces
A Google Maps Webservice API made simple.
Stars: ✭ 56 (-12.5%)
Mutual labels:  rxjava, reactive

GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data. A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type.

Learn more at : http://graphql.org/learn/

OkGraphQl is an Android client implementation, thinked to be easy to use, fluent, and completely modular

Android app on Google Play

Download

Buy Me a Coffee at ko-fi.com

In your module

Download

compile 'com.github.florent37:okgraphql:(last version)'

//dependencies
compile 'io.reactivex.rxjava2:rxjava:2.1.9'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.github.florent37:android-nosql:1.0.0'

Creation

First, initialize you OkGraphQl client with

  • The GraphQl sever url
  • An OkHttpClient (optional)
  • A converter (optional)
OkGraphql okGraphql = new OkGraphql.Builder()
                .okClient(okHttpClient)
                .baseUrl("http://192.168.1.16:8888/graphql")
                .converter(new GsonConverter(new Gson()))
                .build();

Usage

Please note that following examples have been tested on the StarWars GraphQl server : https://github.com/apollographql/starwars-server

Create your GraphQl query with query(string), then execute with enqueue(SuccessCallback, ErrorCallback)

By default the success response is the Json (as String)

okGraphql
        .query("{" +
                "  hero {" +
                "    name" +
                "  }" +
                "}"
        )
        .enqueue(responseString -> {
            //play with your responseString
        }, error -> {
            //display the error
        });

You can also inflate a POJO with the returned Json using .cast(CLASS) This will use the converter assigned to your OkGraphQl

class Character {
     String name;
}
   
class StarWarsResponse {
   Character hero;  
}

okGraphql
        .query("{" +
                "  hero {" +
                "    name" +
                "  }" +
                "}"
        )
        
        .cast(StarWarsResponse.class) //will automatically cast the data json to

        .enqueue(response -> {
            //play with your StarWarsResponse
        }, error -> {
            //display the error
        });

RxJava !

You can also use RxJava methods to your query using .toSingle()

okGraphql
         .query(
                 "Hero($episode: Episode, $withFriends: Boolean!) {" +
                         "  hero(episode: $episode) {" +
                         "    name" +
                         "    friends @include(if: $withFriends) {" +
                         "      name" +
                         "    }" +
                         "  }"
         )

         .variable("episode", "JEDI")
         .variable("withFriends", false)

         .cast(StarWarsResponse.class) //will automatically cast the data json to
         
         .toSingle()
         .observeOn(AndroidSchedulers.mainThread())
         .subscribe(
                 data -> textView.setText(data.toString()),
                 throwable -> textView.setText(throwable.getLocalizedMessage())
         );

Query Builder

Use Fields Builders instead of Strings to create dynamically your queries

okGraphql

      .query(newField()
              .field(newField("human").argument("id: \"1000\"")
                      .field("name")
                      .field("height")
              )
      )
      
      ...

This example will generate the query :

{
  human(id: "1000") {
    name
    height
  }
}

Mutations

Mutations are easy to execute with OkGraphQl

 okGraphql
          .mutation("CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {" +
                  "  createReview(episode: $ep, review: $review) {" +
                  "    stars" +
                  "    commentary" +
                  "  }" +
                  "}")
          .variable("ep", "JEDI")
          .variable("review", "{ \"stars\": 5, \"commentary\": \"This is a great movie!\"")
          .enqueue(responseString -> {
              text1.setText(responseString);
          }, error -> {
              text1.setText(error.getLocalizedMessage());
          });

Fragments

Use .fragment(code) to append a fragment on your request

okGraphql

                .body("{" +
                        "  leftComparison: hero(episode: EMPIRE) {" +
                        "    ...comparisonFields" +
                        "  }" +
                        "  rightComparison: hero(episode: JEDI) {" +
                        "    ...comparisonFields" +
                        "  }" +
                        "}"
                )

                .fragment("comparisonFields on Character {" +
                        "  name" +
                        "  appearsIn" +
                        "  friends {" +
                        "    name" +
                        "  }" +
                        "}")

                .enqueue(responseString -> {
                    query_hero_enqueue.setText(responseString);
                }, error -> {
                    query_hero_enqueue.setText(error.getLocalizedMessage());
                });

Cache

//TODO will use https://github.com/florent37/Android-NoSql

Credits

Author: Florent Champigny

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2016 florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].