Add wildcard path for `@inject` directive
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.5k
- Forks
- 468
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 2
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Nuwave\Lighthouse\Schema\Directives\InjectDirective and its use of argument paths, then read Nuwave\Lighthouse\Execution\Arguments\ArgumentSet, especially addValue. Compare the current behavior with Laravel data_fill for wildcard paths, and verify that nested HasMany inputs receive injected values without breaking existing paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, laravel, php
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100