Hi there,
Trying to migrate from Folklore to your forked version as I need stuff like privacy and authorization. And while most work I'm running into an issue when i use a Type::listOf(Type::string()) on one of my arguments in a mutation.
I've tried to backtrace it and it seems to be in the SelectFields.php on line 123 there is a call to a method that doesn't exist, I looked in Folklore's lib to see if I could get it from there but it turns out this file doesn't even exist there.
Any chance you can help me figure out what going wrong?
` namespace App\GraphQL\Mutation;
use GraphQL;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Mutation;
use App\Wishlist;
use Illuminate\Support\Facades\DB;
class AttachWishesToWishlistMutation extends Mutation
{
protected $attributes = [
'name' => 'attachWishesToWishlist'
];
public function type()
{
return GraphQL::type('Wishlist');
}
public function args()
{
return [
'wishId' => ['name' => 'wishId', 'type' => Type::listOf(Type::string())],
'wishlistId' => ['name' => 'wishlistId', 'type' => Type::string()],
];
}
public function rules()
{
return [
'wishId' => ['required'],
'wishlistId' => ['required'],
];
}
public function resolve($root, $args)
{
$wishlist = Wishlist::find($args['wishlistId']);
if (!$wishlist) {
return null;
}
if (isset($args['wishlistId'])) {
foreach ($args['wishId'] as $wishId) {
$exists = DB::table('wishlist_wishes')
->whereWishId($wishId)
->whereWishlistId($args['wishlistId'])
->count() > 0;
if(!$exists) {
$wishlist->wishes()->attach($wishId);
}
}
}
return $wishlist;
}
}`
It returns the following when using Rebing:
{
"data": {
"attachWishesToWishlist": null
},
"errors": [
{
"message": "Call to undefined method GraphQL\\Type\\Definition\\ListOfType::getField()",
"locations": [
{
"line": 2,
"column": 3
}
]
}
]
}
But if i simply change the Mutation import to Folklore it get the correct data. I'd gladly help out fixing it if you can guide me in the right direction.
It seems to be this piece of code that is having issues:
// If field doesn't exist on definition we don't select it
try {
$fieldObject = $parentType->getField($key);
} catch (InvariantViolation $e) {
continue;
}
Could you show me the whole request?
Certainly :)
This is how my request is formed:
mutation {
attachWishesToWishlist(wishId: ["4", "5"], wishlistId: "3") {
id
title,
wishes {
id,
title
}
}
}
Props for the quick reply btw! 馃憤
Show the Wishlist and Wish Types as well please
WishlistType:
`namespace App\GraphQL\Type;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Type as GraphQLType;
class WishlistType extends GraphQLType
{
protected $attributes = [
'name' => 'Wishlist',
'description' => 'A wishlist'
];
/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;
public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::string()),
'description' => 'The id of the wishlist'
],
'title' => [
'type' => Type::string(),
'description' => 'The title of the wishlist'
],
'description' => [
'type' => Type::string(),
'description' => 'The description of the wishlist'
],
'owner' => [
'type' => \GraphQL::type('User'),
'description' => 'The owner of the wishlist'
],
'followers' => [
'type' => Type::listOf(\GraphQL::type('User')),
'description' => 'Users following the wishlist'
],
'comments' => [
'type' => Type::listOf(\GraphQL::type('Comment')),
'description' => 'Comments posted to the wishlist'
],
'wishes' => [
'type' => Type::listOf(\GraphQL::type('Wish')),
'description' => 'Wishes attached to the wishlist'
]
];
}
protected function resolveOwnerField($root, $args)
{
return $root->user;
}
protected function resolveFollowersField($root, $args)
{
return $root->followers;
}
protected function resolveWishesField($root, $args)
{
return $root->wishes;
}
protected function resolveCommentsField($root, $args)
{
return $root->comments;
}
}`
WishType:
`namespace App\GraphQL\Type;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Type as GraphQLType;
class wishType extends GraphQLType
{
protected $attributes = [
'name' => 'Wish',
'description' => 'A wish'
];
/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;
public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::string()),
'description' => 'The id of the wish'
],
'title' => [
'type' => Type::string(),
'description' => 'The title of the wish'
],
'description' => [
'type' => Type::string(),
'description' => 'The description of the wish'
],
'url' => [
'type' => Type::string(),
'description' => 'The url of the wish'
],
'owner' => [
'type' => \GraphQL::type('User'),
'description' => 'The owner of the wish'
],
'wishlists' => [
'type' => Type::listOf(\GraphQL::type('Wishlist')),
'description' => 'Wishlists this wish is attached to'
],
];
}
protected function resolveOwnerField($root, $args)
{
return $root->user;
}
protected function resolveWishlistsField($root, $args)
{
return $root->wishlists;
}
}`
Opened up the source here: https://gitlab.com/doshdk/wishlist-backend/tree/feature/rebing
Hi, sorry for the late reply. Try removing the resolveWishesField perhaps?
I am encountering the exact same error after switching from the Folklore package too. Removing the resolveWishesField should not be the fix since I do not have extra resolve functions in my code.
Did you end up finding a solution yet?
Ok, resolved it myself. Add the corresponding model to the type attributes array and everything works perfectly.
@DiederikvandenB Can you show an example of that?
@DiederikvandenB @rebing what if the type does not reference a model ?
Most helpful comment
Ok, resolved it myself. Add the corresponding
modelto the typeattributesarray and everything works perfectly.