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

internal: expects an array error with array type #1157

Closed
happy-machine opened this issue Nov 29, 2022 · 7 comments
Closed

internal: expects an array error with array type #1157

happy-machine opened this issue Nov 29, 2022 · 7 comments
Labels
question Further information is requested

Comments

@happy-machine
Copy link

happy-machine commented Nov 29, 2022

Hi really struggling with this would really appreciate your help

My parent resolver is giving me the error: internal: expects an array

I am iterating through the fields in the dynamic version .. this is a simplified version where im returning a hard coded value simulating what im expecting to return:

  for (key, val) in fields.iter() {
    let field = Field::new(
        key.to_string(),
         TypeRef::named_list(TypeRef::STRING),
        |ctx:ResolverContext| FieldFuture::new(async move {
          Ok(Some(Value::from(vec!("boom", "town"))))
        })
    );
    model = model.field(field);
  }

I can't return an array literal because the trait bound async_graphql::Value: std::convert::From<[&str; 2]> is not satisfied so i can't easily test if the problem is it expects an actual array rather than a vec

Can you help?

@happy-machine happy-machine added the question Further information is requested label Nov 29, 2022
@sunli829
Copy link
Collaborator

You need to convert all elements to Value first

Ok(Some(Value::List(
    vec!["boom", "town"].into_iter().map(Value::from).collect(),
)))

@happy-machine
Copy link
Author

Thanks for your quick response sunli : )

I've just tried that, with:

Ok(Some(Value::List(vec!("boom", "town").into_iter().map(Value::from).collect())))

And that gives the same error:
"internal: expects an array"
Screenshot 2022-11-30 at 09 20 15

@happy-machine
Copy link
Author

This also doesn't work although both pass Rust analyser Ok(Some(Value::List(vec!(Value::from("testing".to_string()), Value::from("testing".to_string())))))

@sunli829
Copy link
Collaborator

sunli829 commented Nov 30, 2022

Sorry I was wrong😂, the list resolver does not recognize Value::List, you should do it like this:

FieldValue::list(vec!["boom", "town"].into_iter().map(FieldValue::value))

This example can help you:

https://github.com/async-graphql/examples/tree/4765773e690ff1633b6222d91e8f81baf700739d/models/dynamic-starwars

@sunli829
Copy link
Collaborator

I will support Value::List in v5.0.2

@sunli829
Copy link
Collaborator

Released in v5.0.2

@happy-machine
Copy link
Author

happy-machine commented Nov 30, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants