0

Here are my inputs for nested mutation:

input ActivityInput {
  id: ID
  user_id: ID
  goal: String
}

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

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

And here is my mutation:

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

I need to inject user.id into Activity input, but don't know how to use @inject for array inputs. I've tried the code above but didn't succeed. How can I achieve my goal?

Alireza A2F
  • 519
  • 4
  • 26
  • `@inject` is a [repeatable directive](https://github.com/nuwave/lighthouse/blob/0d8f0fb8a3dd2791dda4c772f3db4b53ee072fb3/src/Schema/Directives/InjectDirective.php#L34), so you should be able to use it multiple times. – Alex Jun 18 '21 at 10:46
  • @AlexBouma how can I use `@inject` for array input? – Alireza A2F Jun 19 '21 at 07:14

1 Answers1

0

Not a solution for your problem, but it could be a workaround:

I was facing a similar problem. To write a Chat-Message the user updates the Chat by adding a new Message and i want to inject the user.id from context as author_id.

Using lighthouse @nest directive did the job for me.

updateChat(id: ID! @eq input: ChatOperations @nest): Chat @update @inject(context: "user.id" name:"input.newMessage.author_id")

The Chat operations input:

inputChatOperations {
    newMessage: CreateMessageInput @create(relation: "messages")
}
Taylor
  • 2,981
  • 2
  • 29
  • 70
FaSe22
  • 1
  • 1
  • Thanks for that answer but I am having difficulties implementing this. Any chance you can give a but more details? Thanks! – Doud Aug 14 '22 at 13:43
  • I think I was able to implement this. Now I have to figure out how to do this with an array of object in the nested mutation. – Doud Aug 15 '22 at 08:28
  • Nice to hear! Let us know if you find a solution for arrays pls. Unfortunately, I haven't found one yet – FaSe22 Aug 16 '22 at 06:03
  • I think the solution is here : https://github.com/nuwave/lighthouse/issues/1879. But I haven't been able to implement this. Good luck if you give it a shot :) – Doud Aug 16 '22 at 16:44