Git Product home page Git Product logo

retrofit-graphql's Introduction

Retrofit Converter - With GraphQL Support     Codacy Badge   Build Status

Seeing how we already have a really powerful type-safe HTTP client for Android and Java Retrofit why not use it and extend it's functionality, this project is a retrofit converter which uses annotations to inject .graphql query or mutation file contents into a request body along with any GraphQL variables.

Why This Project Exists?

Many might wonder why this exists when an android GraphQL library like Apollo exists. Unfortunately Apollo for Android still lacks some basic but important features/functionality which led to the following questions about General Design Questions Regarding Apollo, Polymorphic Type Handling and Non Shared Types. Don't get me wrong Apollo is not inferior any way, it has amazing features such as:

  • Code Generation (Classes and Data Types)
  • Custom Scalar Types
  • Cached Responses

But since model classes are automatically generated for you, the developer loses some flexibility, such as use of generics, abstraction and inheritance. Also Android Performance best practice suggests that developers should use StringDef and IntDef over enums and here's why, with the exception of kotlin especially when using R8.

Strangely there are tons of simple examples all over Medium using apollo graphql for Android, but none of them address these issues because most of them just construct a simple single resource request demo application. These look just fine at first glance until you start working with multiple data types and apollo starts generating classes for every fragment and query even if the data models are the same, or share similar properties.

See a list of changes from here


How Everything Works

Getting Started

  • Add the JitPack repository to your build file
allprojects {
    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
}
  • Add the dependency
dependencies {
    implementation 'com.github.anitrend:retrofit-graphql:{latest_version}'
}
  • Optional R8 / ProGuard Rules

If you are using R8 the shrinking and obfuscation rules are included automatically.

ProGuard users must manually copy the options from this file.

You might also need retrofit rules and it's dependencies (OkHttp and Okio)

Examples

Define, your .graphql files for your GraphQL queries, fragments, and mutations e.t.c.

If you use insomnia you can use this tool to generate your workspaces into directories and files insomnia-graphql-generator. After you can simply place the generated content into your assets folder e.g.:

N.B. You might find this too useful too JetBrains JS GraphQL - Plugin

For more instructions on how to setup the sample app and other examples with file uploads, persisted queries, custom loggers, custom graphql files location (outside assets) please visit the projects wiki page

Screenshots

retrofit-graphql's People

Contributors

wax911 avatar dependabot-preview[bot] avatar eschlenz avatar krillsson avatar cilenco avatar rrva avatar

Watchers

James Cloos avatar

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.