2 releases

0.1.0 Mar 6, 2021
0.1.0-alpha.0 Apr 9, 2020

#41 in #introspection

MIT/Apache

510KB
13K SLoC

Rust 6.5K SLoC // 0.0% comments GraphQL 6.5K SLoC // 0.0% comments

This crate allows you to statically generate all files needed to use artemis. While you could write these by hand, they're quite complex and hand-writing can easily introduce errors, so this module allows you to instead have them generated automatically from .graphql files. All you need apart from the files is an introspected schema in JSON or .graphql format, or alternatively a server that has introspection enabled. Note that the second option requires the introspect feature to be enabled.

Usage

use artemis_build::CodegenBuilder;

CodegenBuilder::new()
    .introspect_schema("http://localhost:8080/graphql", None, Vec::new())
    .unwrap()
    .add_query("my_query.graphql")
    .with_out_dir("src/queries")
    .build();

The only required option is the schema - in this case we're introspecting one from http://localhost:8080/graphql, with no authorization header and no extra headers - but if you don't call add_query at least once the code generator won't do much. The out dir specifies the directory to output your query module to. It will generate a mod.rs in this directory, along with a file for each query and a global query enum for WASM support. Make sure this directory doesn't already have a mod.rs or it will be overridden.

The output directory defaults to OUT_DIR, but for good autocomplete I recommend putting the files somewhere in src where your IDE picks them up.

For more information see each function definition.

Dependencies

~2–16MB
~207K SLoC