graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Dependencies to query file and schema file are not tracked by the compiler when deriving `GraphQLQuery`

Open upsuper opened this issue 6 years ago • 8 comments

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.

upsuper avatar Jan 12 '19 10:01 upsuper

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).

theduke avatar Jan 15 '19 03:01 theduke

Thanks for the trick! We should definitely do this. There could be a compile time impact with huge schemas, but let's see.

tomhoule avatar Jan 15 '19 12:01 tomhoule

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.

tomhoule avatar Jan 15 '19 12:01 tomhoule

You can just use an absolute path.

upsuper avatar Jan 15 '19 19:01 upsuper

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.

tomhoule avatar Feb 12 '19 20:02 tomhoule

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.

tomhoule avatar Mar 21 '19 15:03 tomhoule

See also #117 which resolved to just mention this limitation in the readme.

mathstuf avatar Mar 21 '19 20:03 mathstuf

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.

tomhoule avatar Mar 21 '19 20:03 tomhoule