Hi,
I have two models Account and User.
The relation is: account has many users
My type definitions:
type Account {
id: ID!
limits: Array
}
type User {
id: ID!
account: Account @belongsTo
}
type Query {
me: User @auth
}
and I make a query:
query User {
me {
email
account {
id
limits
}
}
}
After execute I got an error:
Argument 1 passed to GraphQL\Executor\Executor::completeValueCatchingError() must be an instance of GraphQL\Type\Definition\Type, null given, called in /var/www/app/vendor/webonyx/graphql-php/src/Executor/Executor.php on line 721
because the limits is a getter in Account model.
Do you have a solution for use getters?
@mits87 did you define that relationship resolver on your Eloquent model?
I don't believe limits: Array is valid,
Do you maybe want limits: [String] or similar?
Ohhh yes @hailwood you are right. But unfortunately my PHP getter returns data like:
[
['key1'] => 'v1',
['key2'] => 'v2'
]
then how should I get this array by graphql query?
Hi @mits87,
I'm not sure how to help here, but there seems something wrong with the getter return data from your previous comment as I've never seen array keys being arrays themselves, are you sure your previous code sample is correct?
Or should it be written as below?
[
[ 'key1' => 'v1' ],
[ 'key2' => 'v2' ]
]
If the limits value is indeed an array, you must have some kind of relation with the actual limits model, right? I've been using the array type (which serializes to a json) with success as described here: https://laravel.com/docs/5.6/eloquent-mutators#array-and-json-casting
This will require a custom resolver if I'm not mistaken to get the results as a real array in your graphql output.
Hope this helps..
@mits87 Are we able to close this issue or are you still experiencing some problems? Let me know if you have any questions!!
yes, you can close the issue
Most helpful comment
I don't believe
limits: Arrayis valid,Do you maybe want
limits: [String]or similar?