我在初步實施中遇到了困難。 我的問題是,下面的構建無法生成apollo目錄。
用這個gradle(應用程式級別)
plugins {
id 'com.android.application'/span>
id 'kotlin-android'
id'kotlin-kapt'
id 'com.apollographql.apollo'
}
android {
compileSdk31
defaultConfig {
applicationId "com.xxxx.xxxx"。
minSdk 21
targetSdk 31
版本代碼 1
版本名稱 "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"。
}
buildTypes {
發布 {
minifyEnabledfalse
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'。
}
}
編譯選項 {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'/span>
}
}
依賴性 {
實作 'androidx.core:core-ktx:1.6.0'/span>
實作 'androidx.appcompat:appcompat:1.3.1'/span>
實作 'com.google.android.material:material:1.4.0'/span>
實作 'androidx.constraintlayout:constraintlayout:2.1.0'/span>
testImplementation 'junit:junit:4. '/span>
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'/span>
//核心運行時的依賴性。
實作"com.apollographql.apollo:apollo-runtime:2.5.9"
// Coroutines extensions for easier asynchronicity handling
實作"com.apollographql.apollo:apollo-coroutines-support:2.5.9"。
}
apollo {
generateKotlinModels.set(true)
}
而這個gradle
buildscript {
資源庫 {
google()
mavenCentral()
}
依賴性 {
classpath "com.android.tools.build:gradle:7.0.2"/span>。
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"。
classpath "com.apollographql.apollo:apollo-gradle-plugin:2.5.9"。
}
}
任務 clean( type: 洗掉) {
delete rootProject.buildDir {
}
使用這個schema.graphql
schema {
查詢。查詢 查詢
}
type Continent {
code: ID!
countries: [Country!]!
name: String!
}
type Country {
capital: String
code: ID!
大陸。Continent!
貨幣。String!
emoji: String!
emojiU: String!
languages: [Language!]!
name: String!
native: String!
phone: String!
states: [State!]!
}
type Language {
code: ID!
name: String!
native: String: String
rtl: Boolean!
}
type Query {
大陸(代碼: ID!) Continent!
Continents(filter: ContinentFilterInput)。) [Continent!]!
countries(filter: CountryFilterInput)。) [Country!]!
country(code: ID!) Country!
language(code: ID!)。Language: Language!
languages(filter: LanguageFilterInput)。) [Language!]!
}
type State {
code: String State code: String
country: Country!
name: String!
}
enum CacheControlScope {
PRIVATE CacheControlScope ?
PUBLIC[/span
}
input ContinentFilterInput {
代碼。StringQueryOperatorInput
}
input CountryFilterInput {
代碼。StringQueryOperatorInput
大陸。StringQueryOperatorInput StringQueryOperatorInput
貨幣。StringQueryOperatorInput 貨幣: StringQueryOperatorInput
}
input LanguageFilterInput {
代碼。StringQueryOperatorInput LanguageFilterInput { code: code.
}
input StringQueryOperatorInput {
eq: String String
glob: String[/span]> String[/span]>
in: [String]
ne: String] ne: [String
nin: [String] nin: [String]
regex: String] regex: [String
}
"`Upload`標量型別代表一個檔案上傳。"。
scalar Upload
由這個配置生成的
{
"name": " Untitled GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"默認GraphQL端點": {
"url": "https://countries.trevorblades.com/",
"headers": {
"user-agent": "JS GraphQL"
},
"inrospect": false
}
}
} }
}
我不能生成Apollo檔案夾

uj5u.com熱心網友回復:
為什么你把你發布的代碼寫成schema.graphql
?
在我的例子中,你可以找到下面的例子。
在我的例子中,你可以找到一個國家串列的查詢和一個國家細節的查詢。
CountryList.graphql
query CountriesList {
國家 {
code
名稱
大陸{
code
名稱
}
語言{
code
名稱
}
表情符號
}
}
CountryDetail.graphql
query CountryDetail($code:ID! ) {
country(code: $code) {
code: $code
name: $code
phone phone
洲{
code
name
}
capital capital
貨幣 貨幣
languages{
code
name
}
emoji }
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/318691.html
標籤: