lighthouse: Argument names in nested mutations conflict with non-relation methods on the model
Describe the bug I am using the Spatie Permissions package and there is a ‘guard’ field on the Role class. When I try to return that field with a query, it will run the Model::guard() method.
Expected behavior Return guard field from the database
Schema
#types
type Role{
id: ID!
name: String!
guard: String
}
#Inputs
input AddRoleInput {
name: String! @rules(apply: ["required"])
guard: String
}
input EditRoleInput {
id: ID! @rules(apply: ["required"])
name: String
guard: String
}
#Add Queries to Base Query
extend type Query {
roles: [Role!]! @all
role(id: ID! @eq): Role! @find
}
#Add Mutations to Base Mutation
extend type Mutation {
addRole(input: AddRoleInput!): Role! @create(flatten: true)
editRole(input: EditRoleInput!): Role! @update(flatten: true)
#editRoles(
# ids: [ID!]!
# input: EditUsersInput!): [User!]! @bulk(flatten: true)
deleteRole(id: ID!): Role! @delete
deleteRoles(id: [ID!]!): [Role!]! @delete
}
Output/Logs
TypeError: Too few arguments to function Illuminate/Database/Eloquent/Model::guard(), 0 passed in /var/www/simple-rmm-appeval()'d code on line 1 and exactly 1 expected
Environment
Lighthouse Version: 2.6.3 Laravel Version:5.7.16 PHP Version: 7.2.12
Additional context
This seems to be the method it is getting caught up on. I’m not sure if there is a way to check if the method exists only on the model child class.
protected static function extractHasManyArgs(Model $model, Collection $args): Collection
{
return $args->partition(function ($value, $key) use ($model) {
return method_exists($model, $key) && ($model->{$key}() instanceof HasMany);
});
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (14 by maintainers)
Performance for nested mutations won’t be great anyways. Let’s try a naive approach first and possibly optimize if needed.