Могу ли я использовать схему .gql в Apollo Android? (Не генерация классов) - PullRequest
0 голосов
/ 13 марта 2020

Я сталкиваюсь с проблемами при попытке настроить запросы GraphQL с помощью Apollo Android. У меня есть схема .gql вместо схемы json. Мне удалось настроить его с помощью клиента Apollo iOS, поэтому я могу только предполагать, что схема в порядке, и что Apollo Android поддерживает это. (Однако я не смог найти что-нибудь подходящее в их документации.)

В настоящее время проект создается без ошибок, но я не могу найти сгенерированные классы.

В дополнение к настройке ниже Я попытался сгенерировать Kotlin классов, установив для useSemanticNaming значение false и просто бросая грязь в стену, чтобы посмотреть, что прилипнет.

Моя текущая настройка:

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 (приложение):

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'
}

Моя схема:

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

type Query{
    jobs: [Job!]!
}

schema{
    query: Query
}

Файл GraphQL:

query Jobs {
  jobs {
    id
    title
    description
    jobType
    location
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...