-
-
Notifications
You must be signed in to change notification settings - Fork 464
Description
Considering this example schema
type User {
id: ID!
name: String!
comments: [Comment!]! @hasMany
}
type Post {
id: ID!
title: String!
body: String!
user: User! @belongsTo
}
type Comment {
id: ID!
title: String!
body: String!
user: User! @belongsTo
}
input UpdateUserInput {
comments: UpdateCommentsHasMany
}
input UpdateCommentsHasMany {
create: [CreateCommentInput!]
}
input CreateCommentInput {
post_id: ID!
title: String!
body: String!
}
type Mutation @guard {
updateUser(input: UpdateUserInput!): User
@update
@inject(context: "user.id", name: "comments.create.*.user_id")
}It would be awesome if Lighthouse could inject data in the argument set using wildcard in the dot notation, this would cover the nested mutations in the HasMany case, while ensuring that a comment will be created for the authenticated user or a mutation that uses a list of input types.
Of course, today, I can create something like:
input CreateCommentInput {
post_id: ID!
title: String!
body: String!
}
type Mutation @guard {
createComment(input: CreateCommentInput!): Comment!
@create
@inject(context: "user.id", name: "customer_id")
}But, well, this way I'm not using the power of nested mutations.
Maybe I'm wrong, but I think the change needed is just use data_fill instead of Illuminate\Support\Arr::add in the Nuwave\Lighthouse\Schema\Directives\InjectDirective class and rewrite the addValue method of Nuwave\Lighthouse\Execution\Arguments\ArgumentSet class to behave like data_fill as actually it is behaving like Illuminate\Support\Arr::add
Or maybe create a new directive and method.
I'm willing to help with a PR when as soon as I have time available.
Lighthouse Version: 4.9
Laravel Version: 6.12.0