我将https://github.com/leangen/graphql-spqr与 spring-boot java 应用程序一起使用。我可以很容易地找到别名,但如何才能找到原始字段名?
class Food {
@GraphQLQuery(name = "aliasNameX", description = "A food's name")
private String originalName;
...
}
....
@GraphQLQuery(name = "foods") // READ ALL
@Override
public List<Food> getFoods(@GraphQLEnvironment ResolutionEnvironment env) {
DataFetchingFieldSelectionSet selectionSet = env.dataFetchingEnvironment.getSelectionSet();
List<SelectedField> fields = selectionSet.getFields();
for (SelectedField f: fields)
{
System.out.println(f.getName());
}
return foodRepository.findAll();
}
当我运行此代码时,输出看起来像别名字段:“aliasNameX”,...,但我需要像“originalName”这样的原始名称。有没有办法做到这一点?
已解决,根据: