Remove DataFetchers
Follow the conventions of the other sample projects.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package io.spring.sample.graphql;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import graphql.schema.DataFetcher;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DataFetchers {
|
||||
|
||||
@Autowired
|
||||
EmployeeService employeeService;
|
||||
|
||||
public DataFetcher employeeDataFetcher = env -> {
|
||||
return employeeService.getAllEmployees();
|
||||
};
|
||||
|
||||
@Autowired
|
||||
SalaryService salaryService;
|
||||
|
||||
public DataFetcher salaryDataFetcher = env -> {
|
||||
Employee employee = env.getSource();
|
||||
return salaryService.getSalaryForEmployee(employee);
|
||||
};
|
||||
|
||||
public DataFetcher updateSalaryFetcher = env -> {
|
||||
Map<String, String> input = env.getArgument("input");
|
||||
String employeeId = input.get("employeeId");
|
||||
BigDecimal newSalary = new BigDecimal(input.get("salary"));
|
||||
salaryService.updateSalary(employeeId, newSalary);
|
||||
return null;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package io.spring.sample.graphql;
|
||||
|
||||
import graphql.schema.idl.RuntimeWiring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.graphql.boot.RuntimeWiringCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class GraphQLWiring implements RuntimeWiringCustomizer {
|
||||
|
||||
@Autowired
|
||||
DataFetchers dataFetchers;
|
||||
|
||||
@Override
|
||||
public void customize(RuntimeWiring.Builder builder) {
|
||||
builder.type("Query",
|
||||
wiringBuilder -> {
|
||||
return wiringBuilder.
|
||||
dataFetcher("employees", dataFetchers.employeeDataFetcher);
|
||||
});
|
||||
builder.type("Employee",
|
||||
wiringBuilder -> {
|
||||
return wiringBuilder.
|
||||
dataFetcher("salary", dataFetchers.salaryDataFetcher);
|
||||
});
|
||||
builder.type("Mutation",
|
||||
wiringBuilder -> {
|
||||
return wiringBuilder.
|
||||
dataFetcher("updateSalary", dataFetchers.updateSalaryFetcher);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.spring.sample.graphql;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import graphql.schema.idl.RuntimeWiring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.graphql.boot.RuntimeWiringCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SampleWiring implements RuntimeWiringCustomizer {
|
||||
|
||||
final EmployeeService employeeService;
|
||||
|
||||
final SalaryService salaryService;
|
||||
|
||||
public SampleWiring(EmployeeService employeeService, SalaryService salaryService) {
|
||||
this.employeeService = employeeService;
|
||||
this.salaryService = salaryService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void customize(RuntimeWiring.Builder builder) {
|
||||
builder.type("Query", wiringBuilder ->
|
||||
wiringBuilder.dataFetcher("employees", env ->
|
||||
employeeService.getAllEmployees()
|
||||
)
|
||||
);
|
||||
builder.type("Employee", wiringBuilder ->
|
||||
wiringBuilder.dataFetcher("salary", env -> {
|
||||
Employee employee = env.getSource();
|
||||
return salaryService.getSalaryForEmployee(employee);
|
||||
})
|
||||
);
|
||||
builder.type("Mutation", wiringBuilder ->
|
||||
wiringBuilder.dataFetcher("updateSalary", env -> {
|
||||
Map<String, String> input = env.getArgument("input");
|
||||
String employeeId = input.get("employeeId");
|
||||
BigDecimal newSalary = new BigDecimal(input.get("salary"));
|
||||
salaryService.updateSalary(employeeId, newSalary);
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user