GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - AymenSoft/GraphQL

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
app
app
 
 
gradle/wrapper
gradle/wrapper
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

GraphQL

  • simple application to show an exemple of using GraphQL with Kotlin
  • to get the tutorial, read Meduim Article

Dependencies

  • start by implementing dependencies in build.gradle
//apollo  
implementation "com.apollographql.apollo3:apollo-runtime:3.0.0"  
implementation 'com.apollographql.apollo:apollo-android-support:1.0.0'  
// lifecycle  
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'  
//okhttp3  
implementation 'com.squareup.okhttp3:okhttp:4.9.3'  
implementation "com.squareup.okhttp3:logging-interceptor:4.8.1"
  • add Apollo plugin to build.gradle (must be added before kotlin plugin)
plugins {  
  id 'com.android.application'  
  id("com.apollographql.apollo3").version("3.0.0")  
    id 'kotlin-android'  
}
  • in the end of build.gradle, specify the package in which the Kotlin files will be generated.
apollo {  
  packageName.set("com.aymen.graphql")  
}

.graphqlconfig

  • start configuring graphql by creating a .graphqlconfig file in app directory:

app\src\main\graphql

  • add the graphql configuration, and put graphql server url in Default GraphQL Endpoint:
{
  "name": "Untitled GraphQL Schema",
  "schemaPath": "schema.graphqls",
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "http://api.spacex.land/graphql/",
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": true
      }
    }
  }
}

schema.graphqls

  • use Android Studio terminal to import schema.graphqls using this commande:
gradlew :app:downloadApolloSchema --endpoint="http://api.spacex.land/graphql/" --schema=D:\KotlinStudioProjects\GraphQL\app\src\main\graphql\schema.graphqls

usersList.graphql

  • to import users list from graphql server, we need to create a graphql query
  • use SpaceX GraphQL to create a query and copy it
query UsersList($limit:Int!) {
  users(limit: $limit, order_by: {timestamp: desc}) {
    id
    name
    rocket
    timestamp
    twitter
  }
}

Apollo Client Instance

  • create an apollo client instance
private var BASE_URL = "http://api.spacex.land/graphql/"  
  
private val httpClient : OkHttpClient by lazy {  
  val httpLoggingInterceptor = HttpLoggingInterceptor()  
    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)  
    OkHttpClient.Builder()  
        .callTimeout(60, TimeUnit.SECONDS)  
        .readTimeout(60, TimeUnit.SECONDS)  
        .addInterceptor(httpLoggingInterceptor).build()  
}  
  
fun get(): ApolloClient {  
    return ApolloClient.Builder()  
        .serverUrl(BASE_URL)  
        .okHttpClient(httpClient)  
        .build()  
}

get users list

  • to get users list, use users list graphql query:
val response = client.query(UsersListQuery(10)).execute()
  • to get users list from response :
val users = response.data?.users

About

No description, website, or topics provided.

Resources

Readme
Activity

Stars

3 stars

Watchers

1 watching

Forks

7 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.