How to hide few fields based on the region passed in graphql with spring boot

908 Views Asked by At

I have a requirement of passing region and primary key of the table as an input to my graphql query which internally call the jpa repository and retrieves the data.

Now based on the region, I have to hide few fields in my response.

Example

query {
  getEmployee(Id: 1, region : "A") {
    firstName,
    lastName,
    age,
    department
  }
}

For the above graphql request, if user pass region A, then only firstName, lastName and age should be displayed. If user pass region as B, then all the four values should be returned.

is it possible to achieve this in graphql? Please help ! Thank you!!

1

There are 1 best solutions below

0
On BEST ANSWER

Not a graphql role at all

... server must return value for all queried fields, empty (DB record column) values should be resolved to null

... input 'logic' UI for this type can hide 'department' input field - some rules required, defined in/readed some config or hardcoded in component/view

... employee type (and input type) should have 'department' field defined as nullable - without !

... variable passed for field 'department' in create mutation can be undefined