Apollo 中的多模式 Android

Multiple schema in Apollo Android

我在 Android 项目中使用 Apollo 客户端。我有 2 个架构文件,并将它们放在 2 个不同的目录中。

  1. src/main/graphql/com/example/data/search/schema.json
  2. src/main/graphql/com/example/data/user/schema.json

但是当我构建项目通过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
  }
}

希望这对其他人有帮助