Hello there,
Summary
I've a project with multiple services and two schemas and this setup is working fine for UNIX-like system but it does absolutely nothing when running on Windows. The sources aren't generated and it also doesn't output an error if I create a query that shouldn't exist.
Version
Tested in 2.2.0 and 2.4.0.
Description
Given I have a module notifications and I have this configuration with 2 services properly working on MacOS/Linux:
apollo {
service("coffee") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/coffee"
schemaPath = "$rootDir/common/src/main/graphql/com/zeez/app/coffee/schema.json"
}
service("tea") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/tea"
schemaPath = "$rootDir/common/src/main/graphql/com/zeez/app/tea/schema.json"
}
}
Then I've a common module defined this way:
apollo {
service("coffee") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/coffee"
rootPackageName = "com.zeez.app.coffee"
}
service("tea") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/tea"
rootPackageName = "com.zeez.app.tea"
}
}
As I said, this setup is working fine for UNIX-like system but didn't work on Windows. I think it is because how the sourceFolder and schemaPath are resolved.
On Windows the output of the sourceFolder or schemaPath above are something like this:
C:/Zeez/notifications/src/main/graphql/com/zeez/app/coffee
Where on MacOS it will be:
/Users/Bla/Zeez/notifications/src/main/graphql/com/zeez/app/coffee
Additional information
If I write anything in the Query.graphql or even if I put anything in the schema.json the task will pass with success.
Am I doing something wrong or a missing configuration?
Thank you everyone.
Hi 馃憢 , when I've seen similar things, it was most of the times due to either symlinks or case sensitivity.
The fact that it doesn't show an error would hint that the schema is indeed not found so I would focus there first. Is there any uppercase/symlink in the path leading to your schema?
Hello there, @martinbonnin
Thank you for your response. Probably it didn't have. May it will depend on the output of $rootDir I guess.
Example output on Windows:
C:\Folder\project-name\module/src/main/graphql/com/project/app/coffee/schema.json
I've removed sourceFolder property from the my configuration and the following error outputs:
ApolloGraphQL: cannot find a schema file at
C:\Corey\zeez-android/common/src/main/graphql/com/zeez/app/coffee/schema.json.
Tried:
C:\Corey\zeez-android\notifications\src\main\graphql\C:\Corey\zeez-android\common\src\main\graphql\com\zeez\app\coffee\schema.json
As you can see for some reason it is appending the specified schemaPath to the current project dir, which is notifications module. I still think it is because how the method resolveSchema is dealing with the path, but I can be wrong. 馃
Can you try to reduce the problem to only one module? Can you generate models in your common module?
./gradlew :common:generateApolloSources
Does that work ?
Yes, of course!
I've moved some queries to common module and the configuration is the following:
apollo {
service("coffee") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/coffee"
rootPackageName = "com.zeez.app.coffee"
schemaPath = "$projectDir/src/main/graphql/com/zeez/app/coffee/schema.json"
}
service("tea") {
sourceFolder = "$projectDir/src/main/graphql/com/zeez/app/tea"
rootPackageName = "com.zeez.app.tea"
schemaPath = "$projectDir/src/main/graphql/com/zeez/app/tea/schema.json"
}
}
Also tried with .. instead of $projectDir but it result in the same output:
BUILD SUCCESSFUL in 1s
But unfortunately no source has been generated. If I remove the sourceFolder property the build will fail saying it cannot find the schema.json for the given path.
Interesting. So it looks like this is due to the ../ relative path. I'll try to reproduce.
In the meantime, a possible workaround could be to use schemaFile instead which is not resolved relative to src/$foo/graphql. I guess if you put the absolute path there that could help.
@martinbonnin using schemaFile indeed does work.
Thank you for your effort in helping me. I'll check later if it is working properly and doesn't break any existing behavior, but my guess is that it is working pretty well.
Thank you, Martin.
I've tried using schemaFile instead of schemaPath for my multi-module project setup but it didn't work. Sources wasn't getting generated for each module but it does if I put the query in the common module (responsible for having the schema files).
It is a strange behavior and may need further investigation. I'll try to do it when I've more time or maybe I'll create a sample project to investigate this problem.
Besides that I'll keep working with unix-like system until it gets fixed or I found a proper workaround.
Additional information
If I set up everything properly with schemaFile I need to move a for example Query.graphql to the common module, then it will be generated but for an unknow reason, every module which uses apollo for code generation will have the generated source file of this query under its build folder.
I could reproduce this morning. Will keep looking.
Whoopps, I take that back, I made a typo in sourceFolder. Generating sources with a relative path in schemaPath is working. See https://github.com/martinbonnin/apollo-android-samples/tree/main/relativeWindowsPath for an example.
Side note: considering you have a common module that holds your schema and other modules that consume it, it looks like your project could benefit from multi-modules support that just landed in 2.4.0. It's still experimental but I'd love to hear what you think about it.
I'm glad to hear that. I'll try to fix the source generation of my project, if I manage to get it working, I'll jump ahead to try multi-module support!
It seems to be very interesting and I'll give a try.
Question, relative will do the work whereas absolute path (the way I'm doing right now $projectDir/project/bla/schema) shouldn't? Did I got it right?
Anyway, I appreciate your help. I think multi-modules is the way to go! \o/
Question, relative will do the work whereas absolute path (the way I'm doing right now $projectDir/project/bla/schema) shouldn't? Did I got it right?
I'm not sure to be honest. I was able to generate _some_ files using a relative path in schemaPath but I still don't explain why it wasn't working for you in the first place. Maybe the bug is in how sourceFolder is resolved. If you could upload a reproduction repo somewhere, that would be super useful.
Let me know what you think about multi-module, it's still in the phase where we can change APIs so feedback is very welcome!
Oh, that's fine. I'll upload a reproduction repo whenever I can (maybe today or tomorrow, I don't know). In the meanwhile I'll experiment multi-module in my project and I'll create another issue if I found something relevant to the API.
Thanks!
Hey @martinbonnin, I've forked your apollo sample and I was able to reproduce my problem as you can see on this commit: https://github.com/itscorey/apollo-android-samples/commit/694511124df5a0c7a77f74a1132755882a6b471a
The above modification works pretty fine on MacOS (because rootDir starts with /) but on Windows it doesn't (rootDir starts with C:/).
I was able to generate the sources on MacOS but I couldn't do it on Windows because the schemaPath couldn't be found.
--
Was a workaround, I'll try to replace the usage of rootDir and projectDir by ../. I'll also check if the multi-module support fits for my project and I come back to you with a feedback if necessary.
Thank you.
Hey @martinbonnin, I've forked your apollo sample and I was able to reproduce my problem as you can see on this commit
Nice, that'll make fixing the bug way easier, I'll look into this on Monday.
I'll also check if the multi-module support fits for my project and I come back to you with a feedback if necessary.
Thanks 馃憤. I just cleaned up this sample a lot: https://github.com/martinbonnin/apollo-android-samples/commit/24e9ff5222fe1d9681826e3b7205f8e160c55910
This repo is what I use for dogfooding and experimenting stuff which means it isn't always the cleanest but multi-modules should be good now! Let me know how that goes
Released in 2.4.1. Let us know how that goes!
Most helpful comment
Whoopps, I take that back, I made a typo in
sourceFolder. Generating sources with a relative path inschemaPathis working. See https://github.com/martinbonnin/apollo-android-samples/tree/main/relativeWindowsPath for an example.Side note: considering you have a
commonmodule that holds your schema and other modules that consume it, it looks like your project could benefit frommulti-modulessupport that just landed in 2.4.0. It's still experimental but I'd love to hear what you think about it.