android - Apollo Android 中的多个模式

标签 android graphql apollo apollo-client graphql-java

我在 Android 项目中使用 Apollo 客户端。我有 2 个模式文件,我把它们放在了 2 个不同的目录中。

  • src/main/graphql/com/example/data/search/schema.json
  • 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
      }
    }
    

    希望这可以帮助其他人

    关于android - Apollo Android 中的多个模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60689370/

    相关文章:

    java - 此代码段是否会导致无限循环或其他?

    java - 为什么我的应用程序的堆内存比其他应用程序少?

    node.js - 如何避免在错误响应中将错误集合包装在 Apollo Server V2 的错误对象中

    java - 更改从 Strings.xml 文件读取的文本颜色在 Android Eclipse 上的自定义对话框中不起作用

    用于订阅/发布 MQTT(真正的小型消息代理)的 C# 客户端库

    android - 如何修复 ".gradle\nodejs\node-v6.7.0-win-x64\node.exe' '以非零退出值 1 完成”

    express - GraphQL 架构不会导入

    apollo - AWS AppSync 订阅在握手期间失败

    react-native - 来自 apollo-boost 的 ApolloClient 试图分配给只读属性

    javascript - 如何在 Apollo 中组合多个 fetchMore 函数?