我在尝试使用 Apollo Android 设置我的 GraphQL 查询时遇到问题。我有一个 .gql 架构而不是 json 架构。我设法用 Apollo iOS 客户端设置它,所以我只能假设架构很好,并且 Apollo Android 支持这个。(不过,我在他们的文档中找不到任何相关内容。)
目前项目构建没有错误,但我找不到任何生成的类。
除了下面的设置之外,我还尝试生成 Kotlin 类,将 useSemanticNaming 设置为 false 并且通常只是往墙上扔泥看看会粘住什么。
我目前的设置:
build.gradle(根)
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
}
}