-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to define introspection endPoint for each build variant separately? #4490
Comments
Hi! 👋 When configuring your services you can add an If you're already using apollo {
createAllAndroidVariantServices(".", "") {
packageName.set("com.example.apollokotlin.graphql")
if (name.startsWith("debug")) {
srcDir(file("src/debug/graphql/"))
introspection {
endpointUrl.set("https://example.com/debug")
schemaFile.set(file("src/debug/graphql/schema.graphqls"))
}
} else if (name.startsWith("prod")) {
srcDir(file("src/prod/graphql/"))
introspection {
endpointUrl.set("https://example.com/prod")
schemaFile.set(file("src/prod/graphql/schema.graphqls"))
}
} else if (name.startsWith("release")) {
srcDir(file("src/release/graphql/"))
introspection {
endpointUrl.set("https://example.com/release")
schemaFile.set(file("src/release/graphql/schema.graphqls"))
}
}
}
} Note that this creates a service for each variants, including the test ones. If you don't need this granularity you could declare the services manually, like so: apollo {
service("debug") {
srcDir(file("src/debug/graphql/"))
packageName.set("com.example")
outputDirConnection {
connectToAndroidSourceSet("debug")
}
introspection {
endpointUrl.set("https://example.com/debug")
schemaFile.set(file("src/debug/graphql/schema.graphqls"))
}
}
service("release") {
srcDir(file("src/release/graphql/"))
packageName.set("com.example")
outputDirConnection {
connectToAndroidSourceSet("release")
}
introspection {
endpointUrl.set("https://example.com/release")
schemaFile.set(file("src/release/graphql/schema.graphqls"))
}
}
} This will add gradle tasks named |
Thanks! that works. |
If It's true that using this relies on knowing the implementation though. Passing the variant name to the lambda is a good idea, but it may be difficult to make this change in a compatible way. It may be something we can add to the next major version though! |
Sounds good. |
@amansaryal Out of curiosity, how different are your different schemas? Do you also need different queries per variant? If your use case is debug using the pre-prod schema and release using the production one, then I'd recommend using the 2nd approach from @BoD above, specifying explicit "debug" and "release" services. |
@martinbonnin correct. The second approach is what I'm going with as well.
I'm assuming that with schemas in different Here's the use case in a nutshell:I want a common I should be able to configure introspection endpoint for each build variant. |
Gotcha. Many thanks for the additional context 🙏 .
I think that's the key point. If you have shared queries with different schemas, ideally you should put the schemas outside your queries dir:
In that case, I'd recommend doing something like this (factoring code using a nice Kotlin function): fun ApolloExtension.createService(sourceSet: String) {
service(sourceSet) {
srcDir(file("src/main/graphql/")) // You can actually omit this since it's the default
schemaFile.set(file("src/$sourceSet/graphql/schema.graphqls")) // This is required
packageName.set("com.example")
outputDirConnection {
connectToAndroidSourceSet(sourceSet)
}
introspection {
if (sourceSet == "debug") {
endpointUrl.set("https://example.com/debug")
} else {
endpointUrl.set("https://example.com/release")
}
schemaFile.set(file("src/$sourceSet/graphql/schema.graphqls"))
}
}
}
apollo {
createService("debug")
createService("release")
} All in all, I think we could certainly deprecate |
So my assumption was wrong, we can indeed keep the queries and the schema in different places. Gotcha! |
Yes indeed! The plugin tries to find a schema in |
I use introspection to download schema. The endpoint for which changes for every build variant.
I want to know how can I set the schema endpoint dynamically in my gradle script for each build variant in my app?
The text was updated successfully, but these errors were encountered: