Search code examples
androidgraphqlapolloapollo-clientgraphql-java

Multiple schema in Apollo Android


I am using Apollo Client in Android Project. I have 2 schema file and I have put them 2 different directories.

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

But when I build a project to generate code by Apollo It gives me an error:

ApolloGraphQL: By default, only one schema.json file is supported.

and suggest me to use multiple service Build output:

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" 
  } 
}

I have also added this to my build.gradle(app level) file but still shows the same build error.

Please suggest me how can I solve this error


Solution

  • My Problem was resolved with this configuration

    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
      }
    }
    

    Hope this may help others