Open negezor opened 6 months ago
Hi @negezor - good question, this isn't something I've put a lot of thought into.
The approach you suggest certainly seems like a good option - it's not too hard for you, and simple enough for the consumers of your library.
Also is it possible to avoid build.rs in user code? If it will also define its own objects?
I think that depends how much effort you want to put in. All of the derive macros in cynic need to get the schema from somewhere - either the output of that register_schema
function (which goes into the current crates OUT_DIR
) or you can give a path to the schema file to each individual macro.
But if you were really wanting to avoid users dealing with this it might be possible to write your own derives that wrap the built in cynic ones, re-directing them towards your specific schema. Either by prepopulating the schema_path
attribute, or (if you wanted to get more advanced) maybe passing in the path to your libraries OUT_DIR
somehow so it loads the schema from there.
I'm not sure how easy (or even possible) that'd be mind you - but you could try it if you wanted. It might need some API changes in cynic-codegen to expose some things. But I could be open to accepting those, depending on what they are - probably best to talk it through with me after investigating if you do want to go down this route.
Thanks @negezor! I was having the same problem since we were trying to reuse the 'schema' crate in our company (we use a private Cargo registry) but it was difficult since we had to copy the schema files to the dependent crates, which could live in other repos
Hi, I am making a wrapper library for a website with GraphQL API. I would like to ship the schema file with the library so the user doesn't have to download it manually. It only had to define own objects or import ready-made ones.
I have not found clarification in the documentation how this can be done. I would like to ask you as the author of the library. As an option I saw to use
include_str!()
from the main library, then the user would only have to call inbuild.rs
:Also is it possible to avoid
build.rs
in user code? If it will also define its own objects?