pub struct CodegenBuilder { /* private fields */ }
Expand description
Configuration object for code generation
This is used to generate the query structs and modules that are required as well as TypeScript definitions and some static analysis info.
Implementations§
Source§impl CodegenBuilder
impl CodegenBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new codegen builder with default configuration values.
Note that a schema must
be set, either by setting a file or introspecting it.
All other configuration is optional, though it won’t do much if you don’t add any queries.
Sourcepub fn add_query<T: AsRef<Path>>(self, query_path: T) -> Self
pub fn add_query<T: AsRef<Path>>(self, query_path: T) -> Self
Add a query to have the code generator generate a module for it. This is currently opt-in for each file to prevent accidentally generating unneeded code, but a directory based approach may be added later.
Sourcepub fn with_derives_on_variables<T: Into<String>>(self, derives: T) -> Self
pub fn with_derives_on_variables<T: Into<String>>(self, derives: T) -> Self
A comma-separated list of derives to add to the generated Variables
and input structs.
The default derives are Serialize
and Clone
, with Deserialize
added if the target
arch is wasm32
. Adding these here won’t break anything, but it’s redundant.
Sourcepub fn with_derives_on_response<T: Into<String>>(self, derives: T) -> Self
pub fn with_derives_on_response<T: Into<String>>(self, derives: T) -> Self
A comma-separated list of derives to add to the generated ResponseData
and output structs.
The default derives are Deserialize
and Clone
, with Serialize
added if the target
arch is wasm32
. Adding these here won’t break anything, but it’s redundant.
Sourcepub fn with_deprecation_strategy(self, strategy: DeprecationStrategy) -> Self
pub fn with_deprecation_strategy(self, strategy: DeprecationStrategy) -> Self
Set the deprecation strategy used for codegen. Can be used to either warn or completely fail the build if any of your GraphQL queries contain deprecated fields.
Sourcepub fn with_out_dir<T: AsRef<Path>>(self, out_dir: T) -> Self
pub fn with_out_dir<T: AsRef<Path>>(self, out_dir: T) -> Self
Set the output directory for the query module. Defaults to OUT_DIR
, but it’s recommended
to put this in an otherwise empty folder in src
.
Sourcepub fn with_schema<T: AsRef<Path>>(self, schema_path: T) -> Self
pub fn with_schema<T: AsRef<Path>>(self, schema_path: T) -> Self
Sets the schema from a JSON or GraphQL file. The schema should be the result of an
introspection query done against the API you’re generating code for.
If this isn’t set, introspect_schema
must be used.
Sourcepub fn build(self) -> Result<(), BuildError>
pub fn build(self) -> Result<(), BuildError>
Finish the configuration and generate the queries module.
It will generate a exchanges
and a file for each query in the selected output directory.
It’s recommended for that to be an empty directory in src
.
This returns an error if an output directory was not set and OUT_DIR
could not be read,
a schema was not found or an error occurred during codegen or IO.
Trait Implementations§
Source§impl Debug for CodegenBuilder
impl Debug for CodegenBuilder
Source§impl Default for CodegenBuilder
impl Default for CodegenBuilder
Source§fn default() -> CodegenBuilder
fn default() -> CodegenBuilder
Auto Trait Implementations§
impl Freeze for CodegenBuilder
impl RefUnwindSafe for CodegenBuilder
impl Send for CodegenBuilder
impl Sync for CodegenBuilder
impl Unpin for CodegenBuilder
impl UnwindSafe for CodegenBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more