-
Notifications
You must be signed in to change notification settings - Fork 61
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
Methods corresponding to scaffolded fields can no longer return plain arrays, error message cryptic #430
Comments
@MasonD which version of graphql are you using? |
Version 4. |
Yup, we need to coerce array results into ArrayList.. that's the best option here. I'm thinking.... Extension for all dataobjects provides
Then, update all the - |
That seems like a lot of extra introspection to be done on every resolution of a field, if that logic lives in the resolver. Perhaps it can be done at compile time and the resolver can be set as either one that calls obj or one that calls the method and wraps in ArrayList? Or is that premature optimisation... |
Nah, this would all happen in the build. You can pass metadata to the resolver at compile time with |
I've got the same issue when I try to return an array of strings. Wrapping the result in an When returning an
|
It used to be such that the following would work:
But now this causes errors reading
nl2br(): Argument #1 ($string) must be of type string, array given
, which is rather cryptic.The cause is that, now that scaffolded fields are accessed through
ViewableData::obj()
, the array goes through the casting process and by default will be cast as aDBString
, which will usenl2br
whenforTemplate
is called. There doesn't seem to be a way to achieve the desired result besides instead returning an ArrayList.(Creating an ArrayList for me seems like not the optimal solution, because it might necessitate creating an extra function specifically for graphql if there's oither code already expecting getCustomField to return a plain array)
I don't know if this is something to fix in some way (however that might be), but if not I think there need to be warnings in the documentation somewhere, or the error caught and given a better error message, because right now somebody not familiar with the internals of silverstripe-graphql will have no idea how to proceed when encountering this error.
The text was updated successfully, but these errors were encountered: