Skip to content

Commit

Permalink
fix: support fields named str (#1108)
Browse files Browse the repository at this point in the history
Fixes #1107
  • Loading branch information
obmarg authored Nov 30, 2024
1 parent df14335 commit eb39f93
Show file tree
Hide file tree
Showing 11 changed files with 1,461 additions and 1,390 deletions.
4 changes: 2 additions & 2 deletions cynic-codegen/src/use_schema/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ToTokens for FieldOutput<'_> {
impl cynic::schema::Field for #field_marker{
type Type = #field_type_marker;

const NAME: &'static str = #field_name_literal;
const NAME: &'static ::core::primitive::str = #field_name_literal;
}

impl cynic::schema::HasField<#field_marker> for super::super::#parent_marker {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl ToTokens for ArgumentOutput<'_> {
impl cynic::schema::HasArgument<#argument_ident> for super::#field_marker {
type ArgumentType = #schema_type;

const NAME: &'static str = #name;
const NAME: &'static ::core::primitive::str = #name;
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion cynic-codegen/src/use_schema/input_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl ToTokens for FieldOutput<'_> {
impl cynic::schema::Field for #field_marker {
type Type = #field_type_marker;

const NAME: &'static str = #field_name_literal;
const NAME: &'static ::core::primitive::str = #field_name_literal;
}

impl cynic::schema::HasInputField<#field_marker, #field_type_marker> for super::super::#object_marker {
Expand Down
2 changes: 1 addition & 1 deletion cynic-codegen/src/use_schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn use_schema_impl(schema: &Schema<'_, Validated>) -> Result<TokenStr
output.append_all(quote! {
pub struct #ident {}
impl cynic::schema::NamedType for #ident {
const NAME: &'static str = #name;
const NAME: &'static ::core::primitive::str = #name;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion cynic-codegen/src/use_schema/named_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl quote::ToTokens for NamedType<'_> {

tokens.append_all(quote! {
impl cynic::schema::NamedType for #target_struct {
const NAME: &'static str = #graphql_name;
const NAME: &'static ::core::primitive::str = #graphql_name;
}
});
}
Expand Down
54 changes: 27 additions & 27 deletions cynic-codegen/tests/snapshots/use_schema__books.graphql.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: cynic-codegen/tests/use-schema.rs
expression: "format_code(format!(\"{}\", tokens))"
snapshot_kind: text
---
impl cynic::schema::QueryRoot for QueryRoot {}
impl cynic::schema::MutationRoot for MutationRoot {}
Expand All @@ -12,51 +13,51 @@ pub struct MutationType {}
pub struct QueryRoot;
pub struct SubscriptionRoot;
impl cynic::schema::NamedType for Book {
const NAME: &'static str = "Book";
const NAME: &'static ::core::primitive::str = "Book";
}
impl cynic::schema::NamedType for BookChanged {
const NAME: &'static str = "BookChanged";
const NAME: &'static ::core::primitive::str = "BookChanged";
}
impl cynic::schema::NamedType for MutationRoot {
const NAME: &'static str = "MutationRoot";
const NAME: &'static ::core::primitive::str = "MutationRoot";
}
impl cynic::schema::NamedType for QueryRoot {
const NAME: &'static str = "QueryRoot";
const NAME: &'static ::core::primitive::str = "QueryRoot";
}
impl cynic::schema::NamedType for SubscriptionRoot {
const NAME: &'static str = "SubscriptionRoot";
const NAME: &'static ::core::primitive::str = "SubscriptionRoot";
}
#[allow(non_snake_case, non_camel_case_types)]
pub mod __fields {
pub mod Book {
pub struct id;
impl cynic::schema::Field for id {
type Type = super::super::String;
const NAME: &'static str = "id";
const NAME: &'static ::core::primitive::str = "id";
}
impl cynic::schema::HasField<id> for super::super::Book {
type Type = super::super::String;
}
pub struct name;
impl cynic::schema::Field for name {
type Type = super::super::String;
const NAME: &'static str = "name";
const NAME: &'static ::core::primitive::str = "name";
}
impl cynic::schema::HasField<name> for super::super::Book {
type Type = super::super::String;
}
pub struct author;
impl cynic::schema::Field for author {
type Type = super::super::String;
const NAME: &'static str = "author";
const NAME: &'static ::core::primitive::str = "author";
}
impl cynic::schema::HasField<author> for super::super::Book {
type Type = super::super::String;
}
pub struct __typename;
impl cynic::schema::Field for __typename {
type Type = super::super::String;
const NAME: &'static str = "__typename";
const NAME: &'static ::core::primitive::str = "__typename";
}
impl cynic::schema::HasField<__typename> for super::super::Book {
type Type = super::super::String;
Expand All @@ -66,31 +67,31 @@ pub mod __fields {
pub struct mutationType;
impl cynic::schema::Field for mutationType {
type Type = super::super::MutationType;
const NAME: &'static str = "mutationType";
const NAME: &'static ::core::primitive::str = "mutationType";
}
impl cynic::schema::HasField<mutationType> for super::super::BookChanged {
type Type = super::super::MutationType;
}
pub struct id;
impl cynic::schema::Field for id {
type Type = super::super::ID;
const NAME: &'static str = "id";
const NAME: &'static ::core::primitive::str = "id";
}
impl cynic::schema::HasField<id> for super::super::BookChanged {
type Type = super::super::ID;
}
pub struct book;
impl cynic::schema::Field for book {
type Type = Option<super::super::Book>;
const NAME: &'static str = "book";
const NAME: &'static ::core::primitive::str = "book";
}
impl cynic::schema::HasField<book> for super::super::BookChanged {
type Type = Option<super::super::Book>;
}
pub struct __typename;
impl cynic::schema::Field for __typename {
type Type = super::super::String;
const NAME: &'static str = "__typename";
const NAME: &'static ::core::primitive::str = "__typename";
}
impl cynic::schema::HasField<__typename> for super::super::BookChanged {
type Type = super::super::String;
Expand All @@ -100,7 +101,7 @@ pub mod __fields {
pub struct createBook;
impl cynic::schema::Field for createBook {
type Type = super::super::ID;
const NAME: &'static str = "createBook";
const NAME: &'static ::core::primitive::str = "createBook";
}
impl cynic::schema::HasField<createBook> for super::super::MutationRoot {
type Type = super::super::ID;
Expand All @@ -109,18 +110,18 @@ pub mod __fields {
pub struct name;
impl cynic::schema::HasArgument<name> for super::createBook {
type ArgumentType = super::super::super::String;
const NAME: &'static str = "name";
const NAME: &'static ::core::primitive::str = "name";
}
pub struct author;
impl cynic::schema::HasArgument<author> for super::createBook {
type ArgumentType = super::super::super::String;
const NAME: &'static str = "author";
const NAME: &'static ::core::primitive::str = "author";
}
}
pub struct deleteBook;
impl cynic::schema::Field for deleteBook {
type Type = super::super::Boolean;
const NAME: &'static str = "deleteBook";
const NAME: &'static ::core::primitive::str = "deleteBook";
}
impl cynic::schema::HasField<deleteBook> for super::super::MutationRoot {
type Type = super::super::Boolean;
Expand All @@ -129,13 +130,13 @@ pub mod __fields {
pub struct id;
impl cynic::schema::HasArgument<id> for super::deleteBook {
type ArgumentType = super::super::super::ID;
const NAME: &'static str = "id";
const NAME: &'static ::core::primitive::str = "id";
}
}
pub struct __typename;
impl cynic::schema::Field for __typename {
type Type = super::super::String;
const NAME: &'static str = "__typename";
const NAME: &'static ::core::primitive::str = "__typename";
}
impl cynic::schema::HasField<__typename> for super::super::MutationRoot {
type Type = super::super::String;
Expand All @@ -145,15 +146,15 @@ pub mod __fields {
pub struct books;
impl cynic::schema::Field for books {
type Type = Vec<super::super::Book>;
const NAME: &'static str = "books";
const NAME: &'static ::core::primitive::str = "books";
}
impl cynic::schema::HasField<books> for super::super::QueryRoot {
type Type = Vec<super::super::Book>;
}
pub struct __typename;
impl cynic::schema::Field for __typename {
type Type = super::super::String;
const NAME: &'static str = "__typename";
const NAME: &'static ::core::primitive::str = "__typename";
}
impl cynic::schema::HasField<__typename> for super::super::QueryRoot {
type Type = super::super::String;
Expand All @@ -163,7 +164,7 @@ pub mod __fields {
pub struct interval;
impl cynic::schema::Field for interval {
type Type = super::super::Int;
const NAME: &'static str = "interval";
const NAME: &'static ::core::primitive::str = "interval";
}
impl cynic::schema::HasField<interval> for super::super::SubscriptionRoot {
type Type = super::super::Int;
Expand All @@ -172,13 +173,13 @@ pub mod __fields {
pub struct n;
impl cynic::schema::HasArgument<n> for super::interval {
type ArgumentType = super::super::super::Int;
const NAME: &'static str = "n";
const NAME: &'static ::core::primitive::str = "n";
}
}
pub struct books;
impl cynic::schema::Field for books {
type Type = super::super::BookChanged;
const NAME: &'static str = "books";
const NAME: &'static ::core::primitive::str = "books";
}
impl cynic::schema::HasField<books> for super::super::SubscriptionRoot {
type Type = super::super::BookChanged;
Expand All @@ -187,13 +188,13 @@ pub mod __fields {
pub struct mutationType;
impl cynic::schema::HasArgument<mutationType> for super::books {
type ArgumentType = Option<super::super::super::MutationType>;
const NAME: &'static str = "mutationType";
const NAME: &'static ::core::primitive::str = "mutationType";
}
}
pub struct __typename;
impl cynic::schema::Field for __typename {
type Type = super::super::String;
const NAME: &'static str = "__typename";
const NAME: &'static ::core::primitive::str = "__typename";
}
impl cynic::schema::HasField<__typename> for super::super::SubscriptionRoot {
type Type = super::super::String;
Expand Down Expand Up @@ -279,4 +280,3 @@ pub mod variable {
const TYPE: VariableType = VariableType::Named("ID");
}
}

Loading

0 comments on commit eb39f93

Please sign in to comment.