【问题标题】:Kotlin Android Apollo client is not generating Schema classesKotlin Android Apollo 客户端未生成 Schema 类
【发布时间】:2020-01-16 06:45:12
【问题描述】:

我正在开发一个 Android 应用程序。在我的应用程序中,我使用 Apollo 客户端来使用 GraphQL API。当我构建项目时,它不会基于 schema.json 文件生成类。这是我到目前为止所做的。

这是我的应用程序

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'com.apollographql.android'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.memento"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.apollographql.apollo:apollo-runtime:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    compileOnly 'org.jetbrains:annotations:13.0'
    testCompileOnly 'org.jetbrains:annotations:13.0'
}

这是我的大项目

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.41'
    repositories {
        google()
        jcenter()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }

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

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我有 schema.json,这是项目结构

当我构建项目时,会在此文件夹中生成类

但我不能在我的代码中调用这些类。它显示此错误。

如何在我的代码中使用这些类?

【问题讨论】:

  • 您可以在哪里解决这个问题。我在 Kotlin 模型中看到了同样的情况?

标签: android kotlin graphql apollo-client


【解决方案1】:

您需要在与您的 Schema.json 位于同一位置的具有.graphql 扩展名的文件中进行查询。然后重建您的项目,它将生成类。

【讨论】:

    猜你喜欢
    • 2017-10-23
    • 2020-01-19
    • 2019-11-16
    • 2019-07-26
    • 2018-07-23
    • 2018-08-12
    • 2020-05-03
    • 2020-02-27
    • 2012-06-14
    相关资源
    最近更新 更多