gpt4 book ai didi

android - 未生成 Apollo 目录

转载 作者:行者123 更新时间:2023-12-04 17:13:07 32 4
gpt4 key购买 nike

我在最初的实现中遇到了困难。
我的问题是以下构建无法生成 apollo 目录。
有了这个 gradle(应用程序级别)

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'com.apollographql.apollo'
}

android {
compileSdk 31

defaultConfig {
applicationId "com.xxxx.xxxx"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}

}

dependencies {

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'


// The core runtime dependencies
implementation"com.apollographql.apollo:apollo-runtime:2.5.9"
// Coroutines extensions for easier asynchronicity handling
implementation"com.apollographql.apollo:apollo-coroutines-support:2.5.9"

}

apollo {
generateKotlinModels.set(true)
}
而这个gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
classpath "com.apollographql.apollo:apollo-gradle-plugin:2.5.9"

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
使用这个 schema.graphql
schema {
query: Query
}

type Continent {
code: ID!
countries: [Country!]!
name: String!
}

type Country {
capital: String
code: ID!
continent: Continent!
currency: String
emoji: String!
emojiU: String!
languages: [Language!]!
name: String!
native: String!
phone: String!
states: [State!]!
}

type Language {
code: ID!
name: String
native: String
rtl: Boolean!
}

type Query {
continent(code: ID!): Continent
continents(filter: ContinentFilterInput): [Continent!]!
countries(filter: CountryFilterInput): [Country!]!
country(code: ID!): Country
language(code: ID!): Language
languages(filter: LanguageFilterInput): [Language!]!
}

type State {
code: String
country: Country!
name: String!
}

enum CacheControlScope {
PRIVATE
PUBLIC
}

input ContinentFilterInput {
code: StringQueryOperatorInput
}

input CountryFilterInput {
code: StringQueryOperatorInput
continent: StringQueryOperatorInput
currency: StringQueryOperatorInput
}

input LanguageFilterInput {
code: StringQueryOperatorInput
}

input StringQueryOperatorInput {
eq: String
glob: String
in: [String]
ne: String
nin: [String]
regex: String
}


"The `Upload` scalar type represents a file upload."
scalar Upload
此配置生成
{
"name": "Untitled GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "https://countries.trevorblades.com/",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}
我无法生成 Apollo 文件夹
enter image description here

最佳答案

您为什么将发布的代码设置为 schema.graphql ?
您可以在 this GitHub repo 中找到以下示例.
(这是我使用 trevorblades countries APIApollo GraphQL 2.5.9 制作的示例应用程序,所以我认为它非常适合您的需求)

首先你需要download the server's schema使用以下命令(将路径替换为您的应用程序的名称和包)

mkdir -p app/src/main/graphql/com/example/rocketreserver/
./gradlew :app:downloadApolloSchema --endpoint='https://countries.trevorblades.com/' --schema='app/src/main/graphql/com/example/rocketreserver/schema.json'
这将生成 schema.json在指定路径中,之后可以 write all the queries你需要创建像 countries.graphql 这样的文件或 continents.graphql .
确保将它们放在与 schema.json 相同的文件夹中.
enter image description here
在我的示例中,您可以找到一个查询国家列表的查询和一个查询国家详细信息的查询。 CountryList.graphql
query CountriesList {
countries {
code
name
continent{
code
name
}
languages{
code
name
}
emoji
}
}
CountryDetail.graphql
query CountryDetail($code:ID!) {
country(code: $code) {
code
name
phone
continent{
code
name
}
capital
currency
languages{
code
name
}
emoji
}
}
此时您只需要将项目构建到 generate apollo 目录和您定义的模型。
enter image description here

关于android - 未生成 Apollo 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69129285/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com