obi patrick
obi patrick

Reputation: 73

How can I have a field that is of type array in GraphQL?

I need to enter multiple Ids to a field in my mutations. How can I achieve that seeing array is not included in the scalar type. I'm using Laravel lighthouse package.

I have tried to use [] to pass in the Ids but not working.

    mutation{
      syncPermissions(roleId: 1 permissions: [1, 2, 3]){
      name
   }
 }

I expect to access the permissions (in this case Ids) as an array in my resolve method.

Upvotes: 2

Views: 1530

Answers (1)

Albert Haff
Albert Haff

Reputation: 358

You simply wrap the type in [], in your schema.

Example:

extend type Mutation {
    syncPermissions(roleId: Int!, permissions: [Int!])
    @field(resolver: "MyResolver@update")
}

Upvotes: 2

Related Questions