2

I'm encountering issues trying to set up my GraphQL queries using Apollo Android. I have a .gql schema instead of a json schema. I managed to set it up with Apollo iOS client, so I can only assume the schema is fine, and that Apollo Android supports this. (I was unable to find anything relevant in their documentation, though.)

Presently the project builds without error, but I am unable to find any generated classes.

In addition to the setup below I've tried generating Kotlin classes, setting useSemanticNaming to false and just generally throwing mud against the wall to see what will stick.

My current setup:

build.gradle (root)

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath("com.apollographql.apollo:apollo-gradle-plugin:1.3.3")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

build.gradle (app):

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.apollographql.apollo'

repositories {
    jcenter()
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.test.apollotestapplication"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner2"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

apollo {
// NOTE: Putting this inside onCompilationUnit as suggested by the docs resulted in an error.
// NOTE 2: This is where the schema is.
    schemaFile.set(file("/src/main/graphql/com.test.apollotestapplication/schema.gql"))
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation("com.apollographql.apollo:apollo-runtime:1.3.3")
    compileOnly("org.jetbrains:annotations:13.0")
    testCompileOnly("org.jetbrains:annotations:13.0")

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

My schema:

type Job{
    id: ID!
    title: String!
    location: String!
    description: String
    jobType: String!
}

type Query{
    jobs: [Job!]!
}

schema{
    query: Query
}

GraphQL file:

query Jobs {
  jobs {
    id
    title
    description
    jobType
    location
  }
}
Markk
  • 86
  • 3
  • I've worked around this by using an introspection schema in json format rather than the gql schema. I'd still love to know if using a gql schema is possible, though. – Markk Mar 15 '20 at 23:24

0 Answers0