Skip to content

Commit 3910147

Browse files
committed
Make the introspection query compile
1 parent 3ad678e commit 3910147

15 files changed

+2906
-47
lines changed

graphql_query_derive/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ proc-macro = true
88

99
[dependencies]
1010
failure = "*"
11-
log = "*"
1211
quote = "^0.6"
1312
syn = "*"
1413
proc-macro2 = { version = "*", features = ["nightly"] }

graphql_query_derive/src/codegen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use field_type::FieldType;
2-
use quote::ToTokens;
32
use std::collections::BTreeMap;
43

54
#[derive(Debug)]

graphql_query_derive/src/enums.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use proc_macro2::{Ident, Span, TokenStream};
22

3+
pub const ENUMS_PREFIX: &'static str = "RustEnum_";
4+
35
#[derive(Debug, PartialEq)]
46
pub struct GqlEnum {
57
pub name: String,
@@ -14,14 +16,15 @@ impl GqlEnum {
1416
.map(|v| Ident::new(v, Span::call_site()))
1517
.collect();
1618
let variants = &variants;
17-
let name_ident = Ident::new(&self.name, Span::call_site());
19+
let name_ident = Ident::new(&format!("{}{}", ENUMS_PREFIX, self.name), Span::call_site());
1820
let constructors: Vec<_> = variants.iter().map(|v| quote!(#name_ident::#v)).collect();
1921
let constructors = &constructors;
2022
let variant_str = &self.variants;
2123

22-
let name = Ident::new(&self.name, Span::call_site());
24+
let name = name_ident.clone();
2325

2426
quote! {
27+
#[derive(Debug)]
2528
pub enum #name {
2629
#(#variants,)*
2730
Other(String),

graphql_query_derive/src/field_type.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use graphql_parser::schema;
22
use proc_macro2::{Ident, Span, TokenStream};
33
use query::QueryContext;
4-
use heck::CamelCase;
54
use schema::DEFAULT_SCALARS;
5+
use enums::ENUMS_PREFIX;
66

77
#[derive(Debug, PartialEq)]
88
pub enum FieldType {
@@ -14,16 +14,17 @@ pub enum FieldType {
1414
impl FieldType {
1515
/// Takes a field type with its name
1616
pub fn to_rust(&self, context: &QueryContext, prefix: &str) -> TokenStream {
17-
println!("converting that to rust: {:?}", self);
1817
match &self {
1918
FieldType::Named(name) => {
2019
let just_the_prefix = Ident::new(prefix, Span::call_site());
2120
let name_string = name.to_string();
2221

2322
let name = if context.schema.scalars.contains(&name_string) || DEFAULT_SCALARS.iter().find(|elem| elem == &&name_string).is_some() {
24-
name
23+
name.clone()
24+
} else if context.schema.enums.contains_key(&name_string) {
25+
Ident::new(&format!("{}{}", ENUMS_PREFIX, &name_string), Span::call_site())
2526
} else {
26-
&just_the_prefix
27+
just_the_prefix
2728
};
2829

2930
quote!(#name)

graphql_query_derive/src/fragments.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use proc_macro2::{Ident, Span, TokenStream};
2+
use query::QueryContext;
3+
use graphql_parser::query::SelectionSet;
4+
5+
#[derive(Debug, PartialEq)]
6+
pub struct GqlFragment {
7+
pub name: String,
8+
pub on: String,
9+
pub selection: SelectionSet,
10+
}
11+
12+
impl GqlFragment {
13+
pub fn to_rust(&self, context: &QueryContext) -> TokenStream {
14+
let name_ident = Ident::new(&self.name, Span::call_site());
15+
16+
quote!{
17+
#[derive(Debug, Deserialize)]
18+
pub struct #name_ident;
19+
}
20+
}
21+
}

graphql_query_derive/src/interfaces.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use field_type::FieldType;
21
use graphql_parser::query;
32
use objects::GqlObjectField;
43
use proc_macro2::{Ident, Span, TokenStream};
@@ -14,7 +13,7 @@ pub struct GqlInterface {
1413
impl GqlInterface {
1514
pub fn response_for_selection(
1615
&self,
17-
query_context: &QueryContext,
16+
_query_context: &QueryContext,
1817
selection: &query::SelectionSet,
1918
prefix: &str,
2019
) -> TokenStream {

0 commit comments

Comments
 (0)