Skip to content

Commit b384b0c

Browse files
committed
Reduce the errors output for the star wars test
1 parent 4f6acbd commit b384b0c

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

graphql_query_derive/src/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl GqlEnum {
2929

3030
impl ::serde::Serialize for #name {
3131
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
32-
serializer.serialize_str(match *self {
33-
#(#constructors => #variant_str,)*,
32+
ser.serialize_str(match *self {
33+
#(#constructors => #variant_str,)*
3434
#name::Other(s) => s,
3535
})
3636
}

graphql_query_derive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Erro
6868

6969
let result = quote!(
7070
mod #module_name {
71-
const QUERY: &'static str = #query_string;
71+
pub const QUERY: &'static str = #query_string;
7272

7373
#schema_output
7474
}
7575

76-
impl ::graphql_query::GraphQLQuery for #struct_name {
76+
impl<'de> ::graphql_query::GraphQLQuery<'de> for #struct_name {
7777
type Variables = #module_name::Variables;
7878
type ResponseData = #module_name::ResponseData;
7979

80-
fn build_query(variables: &Self::Variables) -> ::graphql_query::GraphQLQueryBody {
81-
GraphQLQueryBody {
80+
fn build_query(variables: &Self::Variables) -> ::graphql_query::GraphQLQueryBody<Self::Variables> {
81+
::graphql_query::GraphQLQueryBody {
8282
variables,
8383
query: #module_name::QUERY,
8484
}

graphql_query_derive/src/schema.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,27 @@ impl Schema {
8181
}
8282

8383
let enum_definitions = self.enums.values().map(|enm| enm.to_rust());
84-
let variables_struct = quote!();
84+
let variables_struct = quote!(#[derive(Serialize)]
85+
pub struct Variables;);
8586
let response_data_fields = context
8687
.query_root
8788
.or(context.mutation_root)
8889
.or(context._subscription_root)
8990
.expect("no selection defined");
9091

92+
use proc_macro2::{Ident, Span};
93+
let object_definitions = self.objects.values().map(|obj| {
94+
let name = Ident::new(&obj.name, Span::call_site());
95+
quote! {
96+
pub struct #name;
97+
}
98+
});
99+
91100
Ok(quote! {
92101
#(#enum_definitions)*
93102

103+
#(#object_definitions)*
104+
94105
#variables_struct
95106

96107
#[derive(Deserialize)]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate graphql_query_derive;
1010
#[doc(hidden)]
1111
pub use graphql_query_derive::*;
1212

13-
trait GraphQLQuery<'de> {
13+
pub trait GraphQLQuery<'de> {
1414
type Variables: serde::Serialize;
1515
type ResponseData: serde::Deserialize<'de>;
1616

0 commit comments

Comments
 (0)