lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

@inject for array inputs

Open alireza-a2f opened this issue 4 years ago • 1 comments

Now you can only use @inject for simple value injections, but it could be very useful if we were able to use @inject for injecting same value into array inputs.

Inputs:

input ActivityInput {
  id: ID
  goal: String
}

input ActivityRelationInput {
  upsert: [ActivityInput]
  delete: [ID]
}

input CustomerInput {
  id: ID
  name: String
  activities: ActivityRelationInput
}

Mutation:

extend type Mutation {
  customerUpsert(input: CustomerInput! @spread): Customer
  @upsert(model: "App\\Models\\Customer")
  @inject(context: "user.id" name: "activities.upsert[].user_id")
}

alireza-a2f avatar Jun 19 '21 07:06 alireza-a2f

This functionality would have to be implemented here: https://github.com/nuwave/lighthouse/blob/0d8f0fb8a3dd2791dda4c772f3db4b53ee072fb3/src/Execution/Arguments/ArgumentSet.php#L239.

The syntax should probably be the same as in array validation: activities.upsert.*.user_id.

What is supposed to happen when the client does not pass nested inputs down to that level?

spawnia avatar Jun 21 '21 07:06 spawnia

Duplicate of https://github.com/nuwave/lighthouse/issues/1206.

spawnia avatar Feb 05 '23 17:02 spawnia