Skip to content

Commit

Permalink
Tweaks to code from #196
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg committed Feb 8, 2021
1 parent f9052b2 commit 003a56c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ all APIs might be changed.
- `QueryFragment` can now be derived for interfaces
- `chrono::NaiveTime` is now supported as a Scalar when the `chrono` feature is
active
- Cynic errors will now suggest possible fixes when you mis-spell or mis-name
a type in your code.

### Changes

Expand Down
2 changes: 1 addition & 1 deletion cynic-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod input_object_derive;
pub mod query_dsl;
pub mod query_module;
pub mod scalar_derive;
pub mod suggestions;

mod error;
mod field_argument;
Expand All @@ -15,6 +14,7 @@ mod generic_param;
mod ident;
mod module;
mod schema;
mod suggestions;
mod type_index;
mod type_path;
mod type_validation;
Expand Down
3 changes: 1 addition & 2 deletions cynic-codegen/src/suggestions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ pub fn guess_field<'a>(
candidates: impl Iterator<Item = &'a str>,
field_name: &str,
) -> Option<&'a str> {
return candidates
.min_by_key(|candidate| hamming(candidate, field_name).unwrap_or(usize::max_value()));
candidates.min_by_key(|candidate| hamming(candidate, field_name).unwrap_or(usize::max_value()))
}

pub fn format_guess(guess_field: Option<&str>) -> String {
Expand Down
14 changes: 3 additions & 11 deletions tests/ui-tests/tests/cases/fragment-guess-validation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn main() {}

#[cynic::query_module(
schema_path = r#"./../../../schemas/starwars.schema.graphql"#,
query_module = "query_dsl",
schema_path = r#"./../../../schemas/starwars.schema.graphql"#,
query_module = "query_dsl"
)]
mod queries {
use super::{query_dsl, types::*};
use super::query_dsl;

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Root")]
Expand All @@ -29,14 +29,6 @@ mod queries {
}
}

#[cynic::query_module(
schema_path = r#"./../../../schemas/starwars.schema.graphql"#,
query_module = "query_dsl",
)]
mod types {}

mod query_dsl {
use super::types::*;

cynic::query_dsl!(r#"./../../../schemas/starwars.schema.graphql"#);
}
14 changes: 0 additions & 14 deletions tests/ui-tests/tests/cases/fragment-guess-validation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: Field fiim does not exist on the GraphQL type Root. Did you mean film?
|
15 | pub fiim: Option<Film>,
| ^^^^

warning: unused import: `types::*`
--> $DIR/fragment-guess-validation.rs:8:28
|
8 | use super::{query_dsl, types::*};
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default

warning: unused import: `super::types::*`
--> $DIR/fragment-guess-validation.rs:39:9
|
39 | use super::types::*;
| ^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Could not find a match for Test in MyUnionType. Did you mean Nested?
error: Could not find a match for Test in MyUnionType. Did you mean TestStruct?
--> $DIR/inline-fragment-exhaustiveness.rs:16:5
|
16 | Test(Test),
Expand Down
23 changes: 11 additions & 12 deletions tests/ui-tests/tests/cases/inputobject-guess-validation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

#![allow(unused_imports)]

fn main() {
}
fn main() {}

#[cynic::query_module(
schema_path = r#"./../../../schemas/github.graphql"#,
query_module = "query_dsl",
schema_path = r#"./../../../schemas/github.graphql"#,
query_module = "query_dsl"
)]
mod queries {
use super::{query_dsl, types::*};
Expand All @@ -24,7 +22,10 @@ mod queries {
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Repository", argument_struct = "PullRequestTitlesArguments")]
#[cynic(
graphql_type = "Repository",
argument_struct = "PullRequestTitlesArguments"
)]
pub struct Repository {
#[arguments(order_by = &args.pr_order)]
pub pull_requests: PullRequestConnection,
Expand Down Expand Up @@ -63,12 +64,11 @@ mod queries {
pub direction: OrderDirection,
pub fieid: IssueOrderField,
}

}

#[cynic::query_module(
schema_path = r#"./../../../schemas/github.graphql"#,
query_module = "query_dsl",
schema_path = r#"./../../../schemas/github.graphql"#,
query_module = "query_dsl"
)]
mod types {
#[derive(cynic::Scalar, Debug, Clone)]
Expand Down Expand Up @@ -100,10 +100,9 @@ mod types {

#[derive(cynic::Scalar, Debug, Clone)]
pub struct X509Certificate(pub String);

}

mod query_dsl{
mod query_dsl {
use super::types::*;
cynic::query_dsl!(r#"./../../../schemas/github.graphql"#);
}
}
12 changes: 6 additions & 6 deletions tests/ui-tests/tests/cases/inputobject-guess-validation.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: Could not find a field fieid in the GraphQL InputObject IssueOrder. Did you mean field?
--> $DIR/inputobject-guess-validation.rs:64:13
--> $DIR/inputobject-guess-validation.rs:65:13
|
64 | pub fieid: IssueOrderField,
65 | pub fieid: IssueOrderField,
| ^^^^^

error: This InputObject is missing these required fields: field
--> $DIR/inputobject-guess-validation.rs:61:5
--> $DIR/inputobject-guess-validation.rs:62:5
|
61 | #[cynic(graphql_type = "IssueOrder")]
62 | #[cynic(graphql_type = "IssueOrder")]
| ^

error[E0277]: the trait bound `&queries::IssueOrder: IntoArgument<Option<_>>` is not satisfied
--> $DIR/inputobject-guess-validation.rs:29:32
--> $DIR/inputobject-guess-validation.rs:30:32
|
29 | #[arguments(order_by = &args.pr_order)]
30 | #[arguments(order_by = &args.pr_order)]
| ^^^^^^^^^^^^^^ the trait `IntoArgument<Option<_>>` is not implemented for `&queries::IssueOrder`

0 comments on commit 003a56c

Please sign in to comment.