CodegenBuilder

Struct CodegenBuilder 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodegenBuilder

Source§

fn default() -> CodegenBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.