graphql-client
graphql-client copied to clipboard
Dependencies to query file and schema file are not tracked by the compiler when deriving `GraphQLQuery`
When using #[derive(GraphQLQuery)], after compiling, if you change the query file or the schema file and run cargo build again, it would do nothing.
This is because compiler is unaware of the change to the file.
To fix this, the macro should insert include_str! or include_bytes! into the generated code, so that compiler can be aware of such build dependency.
See pest-parser/pest#272 as an example of this trick.
Haha @upsuper I just wanted to create an issue for this, also suggesting the pest workaround.
( I remember the pest docs instructing you to add the include_str! manually in the past).
Thanks for the trick! We should definitely do this. There could be a compile time impact with huge schemas, but let's see.
One potential issue is that we work with file paths relative to the Cargo.toml, but include_str! works with paths relative to the current file, I think, so we need to map them somehow.
You can just use an absolute path.
PR #223 addresses this - it doesn't include the schema however, as I'm afraid of the performance impact of including a large schema in all generated modules. It may be irrational though.
This was just released as part of 0.7.0. Let's see if including the schema file in generated code will turn out to be necessary as well.
See also #117 which resolved to just mention this limitation in the readme.
Thanks for the heads up, we should mention this in the README indeed.
edit: I misinterpreted your message apparently, sorry. Anyway, we should track the cargo-based solution because I feel uneasy about the situation with schema files, as mentioned in this thread.