Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic schema: empty array resolved instead of None #1192

Closed
smmoosavi opened this issue Jan 2, 2023 · 0 comments
Closed

dynamic schema: empty array resolved instead of None #1192

smmoosavi opened this issue Jan 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@smmoosavi
Copy link
Contributor

when named_nn_list or named_list resolved to Ok(None), the response should be null but an empty array is returned.

Actual/Expected Behavior

actual:  Object {"hello": Array []}
expected: Object {"hello": Null}

Steps to Reproduce the Problem

use async_graphql::dynamic::*;

pub fn create_schema() -> Schema {
    let query = Object::new("Query");
    let field = Field::new("hello", TypeRef::named_nn_list(TypeRef::STRING), |_ctx| {
        FieldFuture::new(async move {
            return Ok(None as Option<FieldValue>);
        })
    });
    let query = query.field(field);

    let schema = Schema::build(query.type_name(), None, None);
    let schema = schema.register(query);

    schema.finish().unwrap()
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::schema_utils::normalize_schema;

    #[tokio::test]
    async fn test_query() {
        let schema = create_schema();
        let query = r#"{ hello }"#;
        let res = schema.execute(query).await;
        assert_eq!(
            res.data.into_json().unwrap(),
            serde_json::json!({ "hello": null })
        );
    }
}
type Query {
	hello: [String!]
}

schema {
	query: Query
}

Specifications

@smmoosavi smmoosavi added the bug Something isn't working label Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant