Smallrye Graphql : Same query name with different parameters

67 Views Asked by At

I have recently started using smallrye graphql with quarkus. I need same query name with different parameters. And results will be filtered depending upon the input parameter. When I am trying to do this only first query is working

Below is the code I am trying

@Query(value = "Employee")
public List<Employee> getEmployeeById(@Name("id") final List<Integer> employeeIds) {
    return employeeProcess.getEmployeeById(employeeIds);
}

@Query(value = "Employee")
public List<Employee> getEmployeeByDeptId(@Name("deptId") final List<String> deptIds)      {
    return employeeProcess.getEmployeeByDeptId(deptIds);
}

How to have same query name with different parameters?

Thanks in Advance!!

1

There are 1 best solutions below

0
Jan Martiška On

This is not possible with GraphQL in general. Query names have to be unique, overloading is not supported. If you want to have different processing depending on which parameters are passed, you'll need a single query that declares all relevant parameters, allow all of them to be nullable, and then check which ones were passed as null using if statements.