I'm using GraphQL
with SPQR
and I would like to know if anyone knows how to create a dynamic query using Spring Boot
and SPQR
.
I have the following query input:
query findAllAlunosSerie {
findAllAlunosSerie {
id
aluno {
id
nome
idade
}
serie {
id
nome
tipoSerie {
id
nome
}
}
}
}
My goal is to dynamically generate a query based on the user's request, fetching only the requested fields.
Here's my AlunoSerieService
class:
@GraphQLApi
@Lazy
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
@Transactional
public class AlunoSerieService {
private final AlunoSerieMapper alunoSerieMapper;
private final AlunoSerieRepository alunoSerieRepository;
@GraphQLQuery(name = "findAllAlunosSerie")
@Transactional(readOnly = true)
public List<AlunoSerieOutput> findAll(@GraphQLEnvironment ResolutionEnvironment environment) {
return alunoSerieMapper.modelToOutput(alunoSerieRepository.findAll());
}
}
I would like to know if anyone is familiar with a method that can convert this JSON-like
query into a SQL-like
structure, enabling me to perform a SELECT
query and make it less burdensome for the API. Any suggestions or examples?