Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
toolchain: ${{ matrix.rust }}
components: clippy
- name: Check with clippy
run: cargo clippy --all
run: cargo clippy --all --all-features --all-targets

book_examples:
name: Test book examples
Expand Down
1 change: 1 addition & 0 deletions benches/static_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl QueryRoot {
}
}

#[allow(clippy::duplicated_attributes)]
#[derive(Interface)]
#[graphql(
field(name = "id", ty = "&str"),
Expand Down
9 changes: 2 additions & 7 deletions derive/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,19 +913,14 @@ pub struct Description {
pub internal: bool,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub enum NewTypeName {
New(String),
Rust,
#[default]
Original,
}

impl Default for NewTypeName {
fn default() -> Self {
Self::Original
}
}

impl FromMeta for NewTypeName {
fn from_word() -> darling::Result<Self> {
Ok(Self::Rust)
Expand Down
12 changes: 5 additions & 7 deletions derive/src/complex_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ pub fn generate(
.iter()
.nth(1)
.map(|x| {
if let FnArg::Typed(pat) = x {
if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty {
if let Type::Path(path) = elem.as_ref() {
return path.path.segments.last().unwrap().ident
!= "Context";
}
}
if let FnArg::Typed(pat) = x
&& let Type::Reference(TypeReference { elem, .. }) = &*pat.ty
&& let Type::Path(path) = elem.as_ref()
{
return path.path.segments.last().unwrap().ident != "Context";
};
true
})
Expand Down
10 changes: 5 additions & 5 deletions derive/src/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub fn generate(
for arg in item_fn.sig.inputs.iter_mut() {
let mut arg_info = None;

if let FnArg::Typed(pat) = arg {
if let Pat::Ident(ident) = &*pat.pat {
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
remove_graphql_attrs(&mut pat.attrs);
}
if let FnArg::Typed(pat) = arg
&& let Pat::Ident(ident) = &*pat.pat
{
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
remove_graphql_attrs(&mut pat.attrs);
}

let (arg_ident, arg_ty, arg_attrs) = match arg_info {
Expand Down
12 changes: 5 additions & 7 deletions derive/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ pub fn generate(
.iter()
.nth(1)
.map(|x| {
if let FnArg::Typed(pat) = x {
if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty {
if let Type::Path(path) = elem.as_ref() {
return path.path.segments.last().unwrap().ident
!= "Context";
}
}
if let FnArg::Typed(pat) = x
&& let Type::Reference(TypeReference { elem, .. }) = &*pat.ty
&& let Type::Path(path) = elem.as_ref()
{
return path.path.segments.last().unwrap().ident != "Context";
};
true
})
Expand Down
10 changes: 5 additions & 5 deletions derive/src/type_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pub fn generate(
for arg in item_fn.sig.inputs.iter_mut() {
let mut arg_info = None;

if let FnArg::Typed(pat) = arg {
if let Pat::Ident(ident) = &*pat.pat {
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
remove_graphql_attrs(&mut pat.attrs);
}
if let FnArg::Typed(pat) = arg
&& let Pat::Ident(ident) = &*pat.pat
{
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
remove_graphql_attrs(&mut pat.attrs);
}

let (arg_ident, arg_ty, arg_attrs) = match arg_info {
Expand Down
13 changes: 6 additions & 7 deletions derive/src/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,13 @@ pub fn generate(union_args: &args::Union) -> GeneratorResult<TokenStream> {

// Check if the type is a generic parameter which we should
// convert to a concrete type
if let syn::Type::Path(ty_path) = ty {
if let Some(idx) = type_params.iter().position(|p| {
if let syn::Type::Path(ty_path) = ty
&& let Some(idx) = type_params.iter().position(|p| {
p.ident == ty_path.path.segments[0].ident
}) {
let param = &params[idx];
*ty = syn::parse2::<syn::Type>(quote!(#param))
.unwrap();
}
})
{
let param = &params[idx];
*ty = syn::parse2::<syn::Type>(quote!(#param)).unwrap();
}
}
}
Expand Down
64 changes: 32 additions & 32 deletions derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ pub fn get_rustdoc(attrs: &[Attribute]) -> GeneratorResult<Option<TokenStream>>
let mut full_docs: Vec<TokenStream> = vec![];
let mut combined_docs_literal = String::new();
for attr in attrs {
if let Meta::NameValue(nv) = &attr.meta {
if nv.path.is_ident("doc") {
match &nv.value {
Expr::Lit(ExprLit {
lit: Lit::Str(doc), ..
}) => {
let doc = doc.value();
let doc_str = doc.trim();
if let Meta::NameValue(nv) = &attr.meta
&& nv.path.is_ident("doc")
{
match &nv.value {
Expr::Lit(ExprLit {
lit: Lit::Str(doc), ..
}) => {
let doc = doc.value();
let doc_str = doc.trim();
combined_docs_literal += "\n";
combined_docs_literal += doc_str;
}
Expr::Macro(include_macro) => {
if !combined_docs_literal.is_empty() {
combined_docs_literal += "\n";
combined_docs_literal += doc_str;
}
Expr::Macro(include_macro) => {
if !combined_docs_literal.is_empty() {
combined_docs_literal += "\n";
let lit = LitStr::new(&combined_docs_literal, Span::call_site());
full_docs.push(quote!( #lit ));
combined_docs_literal.clear();
}
full_docs.push(quote!( #include_macro ));
let lit = LitStr::new(&combined_docs_literal, Span::call_site());
full_docs.push(quote!( #lit ));
combined_docs_literal.clear();
}
_ => (),
full_docs.push(quote!( #include_macro ));
}
_ => (),
}
}
}
Expand Down Expand Up @@ -226,10 +226,10 @@ pub fn parse_complexity_expr(expr: Expr) -> GeneratorResult<(HashSet<String>, Ex

impl<'a> Visit<'a> for VisitComplexityExpr {
fn visit_expr_path(&mut self, i: &'a ExprPath) {
if let Some(ident) = i.path.get_ident() {
if ident != "child_complexity" {
self.variables.insert(ident.to_string());
}
if let Some(ident) = i.path.get_ident()
&& ident != "child_complexity"
{
self.variables.insert(ident.to_string());
}
}
}
Expand Down Expand Up @@ -355,17 +355,17 @@ pub fn gen_directive_calls(
}

fn extract_directive_call_path(directive: &Expr) -> Option<syn::Path> {
if let Expr::Call(expr) = directive {
if let Expr::Path(ref expr) = *expr.func {
let mut path = expr.path.clone();
if path.segments.pop()?.value().ident != "apply" {
return None;
}
if let Expr::Call(expr) = directive
&& let Expr::Path(ref expr) = *expr.func
{
let mut path = expr.path.clone();
if path.segments.pop()?.value().ident != "apply" {
return None;
}

path.segments.pop_punct()?;
path.segments.pop_punct()?;

return Some(path);
}
return Some(path);
}

None
Expand Down
13 changes: 6 additions & 7 deletions integrations/axum/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ impl IntoResponse for GraphQLResponse {
http::header::CONTENT_TYPE,
HeaderValue::from_static("application/graphql-response+json"),
);
if self.0.is_ok() {
if let Some(cache_control) = self.0.cache_control().value() {
if let Ok(value) = HeaderValue::from_str(&cache_control) {
resp.headers_mut()
.insert(http::header::CACHE_CONTROL, value);
}
}
if self.0.is_ok()
&& let Some(cache_control) = self.0.cache_control().value()
&& let Ok(value) = HeaderValue::from_str(&cache_control)
{
resp.headers_mut()
.insert(http::header::CACHE_CONTROL, value);
}

resp.headers_mut().extend(self.0.http_headers());
Expand Down
4 changes: 2 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
/// }
/// }
/// ```
pub fn look_ahead(&self) -> Lookahead {
pub fn look_ahead(&self) -> Lookahead<'_> {
Lookahead::new(&self.query_env.fragments, &self.item.node, self)
}

Expand Down Expand Up @@ -728,7 +728,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
/// );
/// # });
/// ```
pub fn field(&self) -> SelectionField {
pub fn field(&self) -> SelectionField<'_> {
SelectionField {
fragments: &self.query_env.fragments,
field: &self.item.node,
Expand Down
6 changes: 3 additions & 3 deletions src/dynamic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'a> FieldValue<'a> {
/// If the FieldValue is a list, returns the associated
/// vector. Returns `None` otherwise.
#[inline]
pub fn as_list(&self) -> Option<&[FieldValue]> {
pub fn as_list(&self) -> Option<&[FieldValue<'_>]> {
match &self.0 {
FieldValueInner::List(values) => Some(values),
_ => None,
Expand All @@ -233,7 +233,7 @@ impl<'a> FieldValue<'a> {

/// Like `as_list`, but returns `Result`.
#[inline]
pub fn try_to_list(&self) -> Result<&[FieldValue]> {
pub fn try_to_list(&self) -> Result<&[FieldValue<'_>]> {
self.as_list()
.ok_or_else(|| Error::new(format!("internal: \"{:?}\" not a List", self)))
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a> FieldFuture<'a> {
}

pub(crate) type BoxResolverFn =
Box<(dyn for<'a> Fn(ResolverContext<'a>) -> FieldFuture<'a> + Send + Sync)>;
Box<dyn for<'a> Fn(ResolverContext<'a>) -> FieldFuture<'a> + Send + Sync>;

/// A GraphQL field
pub struct Field {
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> SubscriptionFieldFuture<'a> {
}

type BoxResolverFn =
Arc<(dyn for<'a> Fn(ResolverContext<'a>) -> SubscriptionFieldFuture<'a> + Send + Sync)>;
Arc<dyn for<'a> Fn(ResolverContext<'a>) -> SubscriptionFieldFuture<'a> + Send + Sync>;

/// A GraphQL subscription field
pub struct SubscriptionField {
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ mod tests {
}

impl Animal {
fn to_field_value(&self) -> FieldValue {
fn to_field_value(&self) -> FieldValue<'_> {
match self {
Animal::Dog(dog) => FieldValue::borrowed_any(dog).with_type("Dog"),
Animal::Cat(cat) => FieldValue::borrowed_any(cat).with_type("Cat"),
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl Extensions {
}

#[inline]
fn create_context(&self) -> ExtensionContext {
fn create_context(&self) -> ExtensionContext<'_> {
ExtensionContext {
schema_env: &self.schema_env,
session_data: &self.session_data,
Expand Down
2 changes: 1 addition & 1 deletion src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Display for MetaTypeName<'_> {

impl MetaTypeName<'_> {
#[inline]
pub fn create(type_name: &str) -> MetaTypeName {
pub fn create(type_name: &str) -> MetaTypeName<'_> {
if let Some(type_name) = type_name.strip_suffix('!') {
MetaTypeName::NonNull(type_name)
} else if let Some(type_name) = strip_brackets(type_name) {
Expand Down
9 changes: 2 additions & 7 deletions src/types/maybe_undefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ use crate::{InputType, InputValueError, InputValueResult, Value, registry};
/// # });
/// ```
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Default)]
pub enum MaybeUndefined<T> {
#[default]
Undefined,
Null,
Value(T),
}

impl<T> Default for MaybeUndefined<T> {
fn default() -> Self {
Self::Undefined
}
}

impl<T> MaybeUndefined<T> {
/// Returns true if the `MaybeUndefined<T>` is undefined.
#[inline]
Expand Down
2 changes: 2 additions & 0 deletions tests/error_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ pub async fn test_failure2() {
}
}

#[allow(dead_code)]
struct Query;

#[Object]
impl Query {
#[allow(dead_code)]
async fn failure(&self) -> Result<i32, MyError> {
Err(MyError::Error1)
}
Expand Down
1 change: 1 addition & 0 deletions tests/introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ pub async fn test_introspection_subscription() {
#[tokio::test]
pub async fn test_disable_introspection() {
#[derive(SimpleObject)]
#[expect(dead_code)]
struct Query {
value: i32,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use async_graphql::*;
use static_assertions_next::_core::marker::PhantomData;

#[derive(SimpleObject)]
#[allow(dead_code)]
struct ObjA<'a> {
value: &'a i32,
}

#[expect(dead_code)]
struct ObjB<'a>(PhantomData<&'a i32>);

#[Object]
Expand All @@ -19,12 +21,14 @@ impl<'a> ObjB<'a> {
}

#[derive(Union)]
#[expect(dead_code)]
enum MyUnion1<'a> {
ObjA(ObjA<'a>),
}

#[derive(Interface)]
#[graphql(field(name = "value", ty = "&&'a i32"))]
#[expect(dead_code)]
enum MyInterface<'a> {
ObjA(ObjA<'a>),
}
Loading