0

So how can I do, or is possible to have 2 types on the input fields? For example, I have like:

input UpdatePersonInput {
    first_name: String
    surname: String
    age: Int
}

extend type Mutation {
    updatePerson(id: ID!, input: UpdatePersonInput!): Person! @field(resolver: "App\\GraphQL\\Mutations\\Person@update")
}

On my input, I want a type Int but at the same time want the type null (this type don't exist by my knowledge) to update on DB the field age on Persons (like some people give age and some don't). This is a simple example, but my code is more complex and I can't be checking if the key comes or not in the input like

key_exists('age', $args['input'])

on the resolver method update. I am using lighthouse graphql v4.16.

francisco
  • 1,387
  • 2
  • 12
  • 23

1 Answers1

0

I think you may want to use Arr::get($args, 'age')

Enzo Notario
  • 639
  • 4
  • 9
  • I want the client be able to send me type `null` and I don't want validations on, to see if it exists or not in the array of args like I did it but with php. Example: `$args = [ 'first_name' => 'francisco', 'surname' => 'caldeira', 'age' => **null** ]` or this way, `$args = [ 'first_name' => 'francisco', 'surname' => 'caldeira', 'age' => **24** ]` @enzo-notario – francisco Feb 15 '21 at 18:09
  • 1
    Yes, you are using just `Int`, not `Int!` (note the `!`). So you should be able to pass `null` as value. – Enzo Notario Feb 16 '21 at 22:12