我在 Android 项目中使用 Apollo 客户端。我有 2 个模式文件,我把它们放在了 2 个不同的目录中。
但是当我建立一个项目来通过 Apollo 生成代码时它给了我一个错误:
ApolloGraphQL: By default, only one schema.json file is supported.
并建议我使用 多种服务
构建输出:
ApolloGraphQL: By default, only one schema.json file is supported. Please use multiple services instead:
apollo {
service("search") {
sourceFolder = "/.../app/src/main/graphql/com/example/data/search"
}
service("customer") {
sourceFolder = "/.../app/src/main/graphql/com/example/data/customer"
}
}
我也将此添加到我的
build.gradle
(应用程序级别)文件,但仍显示相同的构建错误。请建议我如何解决此错误
最佳答案
我的问题已通过此配置解决
apollo {
// configure ApolloExtension here
generateKotlinModels.set(false) // Generate Kotlin models for all services
service("search") {
sourceFolder.set("com/example/data/search")
rootPackageName.set("com.example.data.search")
}
service("customer") {
sourceFolder.set("com/example/data/customer")
rootPackageName.set("com.example.data.customer")
}
onCompilationUnit {
// Overwrite some options here for single CompilationUnit if needed
}
}
希望这可以帮助其他人
关于android - Apollo Android 中的多个模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60689370/