-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,072 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
derive/src/args/snapshots/dynamic_graphql_derive__args__test_output__app.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
source: derive/src/args/test_output.rs | ||
expression: output | ||
--- | ||
```rust | ||
struct App(QueryRoot, PostApp); | ||
impl dynamic_graphql::internal::Register for App { | ||
fn register( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry { | ||
let registry = registry.register::<QueryRoot>(); | ||
let registry = registry.register::<PostApp>(); | ||
registry | ||
} | ||
} | ||
impl App { | ||
pub fn create_schema() -> dynamic_graphql::dynamic::SchemaBuilder { | ||
let registry = dynamic_graphql::internal::Registry::new(); | ||
let registry = registry.register::<Self>(); | ||
registry.create_schema() | ||
} | ||
} | ||
impl App { | ||
#[allow(dead_code)] | ||
#[doc(hidden)] | ||
fn __suppress_clippy_error(&self) { | ||
let _ = self.0; | ||
let _ = self.1; | ||
} | ||
} | ||
``` |
93 changes: 93 additions & 0 deletions
93
derive/src/args/snapshots/dynamic_graphql_derive__args__test_output__enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
source: derive/src/args/test_output.rs | ||
expression: output | ||
--- | ||
```rust | ||
enum Example { | ||
Foo, | ||
Bar, | ||
} | ||
impl dynamic_graphql::internal::TypeName for Example { | ||
fn get_type_name() -> std::borrow::Cow<'static, str> { | ||
"Example".into() | ||
} | ||
} | ||
impl dynamic_graphql::internal::InputTypeName for Example {} | ||
impl dynamic_graphql::internal::OutputTypeName for Example {} | ||
impl dynamic_graphql::internal::Enum for Example {} | ||
impl From<&Example> for dynamic_graphql::Value { | ||
fn from(value: &Example) -> Self { | ||
match value { | ||
Example::Foo => { | ||
dynamic_graphql::Value::Enum(dynamic_graphql::Name::new("FOO")) | ||
} | ||
Example::Bar => { | ||
dynamic_graphql::Value::Enum(dynamic_graphql::Name::new("BAR")) | ||
} | ||
} | ||
} | ||
} | ||
impl< | ||
'__dynamic_graphql_lifetime, | ||
> dynamic_graphql::internal::ResolveOwned<'__dynamic_graphql_lifetime> for Example { | ||
fn resolve_owned( | ||
self, | ||
_ctx: &dynamic_graphql::Context, | ||
) -> dynamic_graphql::Result< | ||
Option<dynamic_graphql::FieldValue<'__dynamic_graphql_lifetime>>, | ||
> { | ||
Ok(Some(dynamic_graphql::FieldValue::value(&self))) | ||
} | ||
} | ||
impl< | ||
'__dynamic_graphql_lifetime, | ||
> dynamic_graphql::internal::ResolveRef<'__dynamic_graphql_lifetime> for Example { | ||
fn resolve_ref( | ||
&'__dynamic_graphql_lifetime self, | ||
_ctx: &dynamic_graphql::Context, | ||
) -> dynamic_graphql::Result< | ||
Option<dynamic_graphql::FieldValue<'__dynamic_graphql_lifetime>>, | ||
> { | ||
Ok(Some(dynamic_graphql::FieldValue::value(self))) | ||
} | ||
} | ||
impl dynamic_graphql::internal::FromValue for Example { | ||
fn from_value( | ||
__value: dynamic_graphql::Result<dynamic_graphql::dynamic::ValueAccessor>, | ||
) -> dynamic_graphql::internal::InputValueResult<Self> { | ||
let __value = __value?; | ||
let string_value = __value.enum_name()?; | ||
match string_value { | ||
"FOO" => Ok(Example::Foo), | ||
"BAR" => Ok(Example::Bar), | ||
_ => { | ||
Err( | ||
dynamic_graphql::internal::InputValueError::custom( | ||
format!( | ||
"Unknown variant `{}` for enum `{}`", string_value, < Example | ||
as dynamic_graphql::internal::Enum > ::get_enum_type_name() | ||
.as_ref() | ||
), | ||
), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
impl dynamic_graphql::internal::Register for Example { | ||
fn register( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry { | ||
let object = dynamic_graphql::dynamic::Enum::new( | ||
<Example as dynamic_graphql::internal::Enum>::get_enum_type_name().as_ref(), | ||
); | ||
let field = dynamic_graphql::dynamic::EnumItem::new("FOO"); | ||
let object = object.item(field); | ||
let field = dynamic_graphql::dynamic::EnumItem::new("BAR"); | ||
let object = object.item(field); | ||
registry.register_type(object) | ||
} | ||
} | ||
``` |
90 changes: 90 additions & 0 deletions
90
derive/src/args/snapshots/dynamic_graphql_derive__args__test_output__expand_object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
source: derive/src/args/test_output.rs | ||
expression: output | ||
--- | ||
```rust | ||
struct ExampleQuery<'a>(&'a Query); | ||
impl<'a> ExampleQuery<'a> { | ||
fn __registers( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry { | ||
registry | ||
} | ||
} | ||
impl<'a> dynamic_graphql::internal::ParentType for ExampleQuery<'a> { | ||
type Type = Query; | ||
} | ||
impl<'a> dynamic_graphql::internal::ExpandObject for ExampleQuery<'a> { | ||
fn get_expand_object_name() -> std::borrow::Cow<'static, str> { | ||
"ExampleQuery".into() | ||
} | ||
} | ||
impl<'a> From<&'a Query> for ExampleQuery<'a> { | ||
fn from(target: &'a Query) -> Self { | ||
Self(target) | ||
} | ||
} | ||
impl<'a> dynamic_graphql::internal::RegisterFns for ExampleQuery<'a> { | ||
const REGISTER_FNS: &'static [fn( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry] = &[ExampleQuery::<'a>::__registers]; | ||
} | ||
impl<'a> ExampleQuery<'a> { | ||
#[allow(dead_code)] | ||
#[doc(hidden)] | ||
fn __suppress_clippy_error(&self) { | ||
let _ = self.0; | ||
} | ||
} | ||
impl ExampleQuery<'_> { | ||
fn the_example(&self) -> Example { | ||
Example { | ||
field: "field".to_string(), | ||
} | ||
} | ||
} | ||
impl dynamic_graphql::internal::Register for ExampleQuery<'_> { | ||
fn register( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry { | ||
let registry = registry.register::<Example>(); | ||
let registry = <Self as dynamic_graphql::internal::RegisterFns>::REGISTER_FNS | ||
.iter() | ||
.fold(registry, |registry, f| f(registry)); | ||
let field = dynamic_graphql::dynamic::Field::new( | ||
"theExample", | ||
<Example as dynamic_graphql::internal::GetOutputTypeRef>::get_output_type_ref(), | ||
|ctx| { | ||
dynamic_graphql::dynamic::FieldFuture::new(async move { | ||
let parent = ctx | ||
.parent_value | ||
.try_downcast_ref::< | ||
<Self as dynamic_graphql::internal::ParentType>::Type, | ||
>()? | ||
.into(); | ||
let arg0 = &parent; | ||
let value = ExampleQuery::the_example(arg0); | ||
dynamic_graphql::internal::Resolve::resolve(value, &ctx) | ||
}) | ||
}, | ||
); | ||
let __field_0 = field; | ||
registry | ||
.update_object( | ||
<<Self as dynamic_graphql::internal::ParentType>::Type as dynamic_graphql::internal::Object>::get_object_type_name() | ||
.as_ref(), | ||
<Self as dynamic_graphql::internal::ExpandObject>::get_expand_object_name() | ||
.as_ref(), | ||
|object| { | ||
let object = object.field(__field_0); | ||
object | ||
}, | ||
) | ||
} | ||
} | ||
``` |
48 changes: 48 additions & 0 deletions
48
derive/src/args/snapshots/dynamic_graphql_derive__args__test_output__input_object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
source: derive/src/args/test_output.rs | ||
expression: output | ||
--- | ||
```rust | ||
struct ExampleInput { | ||
pub string: String, | ||
} | ||
impl dynamic_graphql::internal::TypeName for ExampleInput { | ||
fn get_type_name() -> std::borrow::Cow<'static, str> { | ||
"ExampleInput".into() | ||
} | ||
} | ||
impl dynamic_graphql::internal::InputTypeName for ExampleInput {} | ||
impl dynamic_graphql::internal::InputObject for ExampleInput {} | ||
impl dynamic_graphql::internal::Register for ExampleInput { | ||
fn register( | ||
registry: dynamic_graphql::internal::Registry, | ||
) -> dynamic_graphql::internal::Registry { | ||
let registry = registry.register::<String>(); | ||
let object = dynamic_graphql::dynamic::InputObject::new( | ||
<Self as dynamic_graphql::internal::InputObject>::get_input_object_type_name() | ||
.as_ref(), | ||
); | ||
let field = dynamic_graphql::dynamic::InputValue::new( | ||
"string", | ||
<String as dynamic_graphql::internal::GetInputTypeRef>::get_input_type_ref(), | ||
); | ||
let object = object.field(field); | ||
registry.register_type(object) | ||
} | ||
} | ||
impl dynamic_graphql::internal::FromValue for ExampleInput { | ||
fn from_value( | ||
__value: dynamic_graphql::Result<dynamic_graphql::dynamic::ValueAccessor>, | ||
) -> dynamic_graphql::internal::InputValueResult<Self> { | ||
let __value = __value?; | ||
let __object = __value.object()?; | ||
let field0 = dynamic_graphql::internal::FromValue::from_value( | ||
__object.try_get("string"), | ||
) | ||
.map_err(|e| e.into_field_error("string"))?; | ||
Ok(Self { string: field0 }) | ||
} | ||
} | ||
``` |
Oops, something went wrong.