Android Apollo3 Migration - Multiple schemas found error

In migrating from 2.5.5 to 3.1.0 on Android, I’ve hit an issue with having multiple services/schemas. The app reaches out to two GraphQL APIs, and thus has two services. In 2.x, the different services’ packages and folders could be set in the build.gradle, but I haven’t found documentation on how to do that in 3.x. If those docs are out there somewhere, can someone just link me to them? I’ve been unable to find them.

If those docs are missing, I need some help. When I update according to how I read the migration docs, I get the error: java.lang.IllegalStateException: Multiple schemas found: {lists schemas} Use different services for different schemas. Here’s what worked in 2.x in the app/build.gradle :

apollo {
    generateKotlinModels.set(true)
    service("service1") {
        sourceFolder.set("com/proj/app/service1")
        rootPackageName.set("com.proj.app.service1")
    }
    service("service2") {
        sourceFolder.set("com/proj/app/service2")
        rootPackageName.set("com.proj.app.service2")
    }
}

and here’s one example of what’s not working in 3.x (causing the Multiple schemas found error):

apollo {
    service("service1") {
        packageName.set("com.proj.app.service1")
    }
    service("service2") {
        packageName.set("com.proj.app.service2")
    }
}

Another thing I’ve tried that isn’t working is to replace each packageName.set call with the following:

packageNamesFromFilePaths("com/proj/app/service#")
useSchemaPackageNameForFragments.set(true)

but I get the same error. Other things I’ve tried are:

  • put useSchemaPackageNameForFragments above the services instead of in them (same error)
  • removing useSchemaPackageNameForFragments entirely (same error)
  • having all three lines in each service block (causes IllegalStateException)

Any and all help would be greatly appreciated!

Hi :wave:

If you keep the sourceFolder property (same configuration as in v2), it should work:

apollo {
    service("service1") {
        sourceFolder.set("com/proj/app/service1")
        rootPackageName.set("com.proj.app.service1")
    }
    service("service2") {
        sourceFolder.set("com/proj/app/service2")
        rootPackageName.set("com.proj.app.service2")
    }
}

Or is there a specific reason you removed sourceFolder?

1 Like

Thank you! You’re right, I needed the sourceFolder.set calls. For the full fix I just change rootPackageName calls to packageName as well.

I had removed it because the migration docs weren’t clear on whether or not it was needed, and made reference to using packageNamesFromFilePaths, which seems to have a similar function. I didn’t think to try it with them still there. Thanks again!

1 Like