https://github.com/bennyhuo/retroapollo-android
Apollo-Android wrapper like Retrofit for GraphQL.
https://github.com/bennyhuo/retroapollo-android
apollo-android graphql retroapollo-android
Last synced: 3 months ago
JSON representation
Apollo-Android wrapper like Retrofit for GraphQL.
- Host: GitHub
- URL: https://github.com/bennyhuo/retroapollo-android
- Owner: bennyhuo
- Created: 2017-08-03T00:00:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-30T23:11:24.000Z (about 8 years ago)
- Last Synced: 2025-04-14T22:53:58.343Z (about 1 year ago)
- Topics: apollo-android, graphql, retroapollo-android
- Language: Kotlin
- Homepage:
- Size: 198 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RetroApollo-Android
[Apollo-Android](https://github.com/apollographql/apollo-android) wrapper like Retrofit for easy use.
Tested on Apollo-Android 0.4.2. It has been deployed to jCenter:
```groovy
api "com.bennyhuo.retroapollo:retroapollo:0.4.2-beta"
```
## Example
This is based on [Apollo-Android](https://github.com/apollographql/apollo-android), so you should config graphql api as what we do in Apollo-Android.
Suppose we have graphql request below:
```
query RepositoryStatistics($repo: String!, $owner: String!){
repository(name: $repo, owner: $owner) {
stargazers{
totalCount
}
watchers{
totalCount
}
issues{
totalCount
}
}
}
```
We can then create an interface like this:
```kotlin
interface GraphQLService {
fun repositoryStatisticsQuery(@GraphQLQuery("owner") owner: String, @GraphQLQuery("repo") repo: String): Observable
}
```
Just like what we do in retrofit, create an instance of interface by RetroApollo.Builder:
```
val apolloClient by lazy {
//Build the Apollo Client
ApolloClient.builder()
.okHttpClient(OkHttpClient.Builder().addInterceptor(AuthInterceptor()).build())
.serverUrl("https://api.github.com/graphql")
.build()
}
val graphQLService by lazy {
RetroApollo.Builder()
.apolloClient(apolloClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory()
.observableScheduler(AndroidSchedulers.mainThread())
.subscribeScheduler(Schedulers.io()))
.build()
.createGraphQLService(GraphQLService::class)
}
```
That's it! Now we can make request like this:
```kotlin
graphQLService.repositoryStatisticsQuery("enbandari", "RetroApollo")
.subscribe {
...
}
```
# License
```
Copyright 2017 Bennyhuo
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.
```