我正在尝试使用 graphql-spring-boot-starter 构建 GraphQL 服务器,并对 Apollo 跟踪(https://github.com/apollographql/apollo-tracing)感兴趣,它在扩展的跟踪键下添加了额外的数据。
添加跟踪工具后,我的响应没有任何变化。我在这里错过了什么吗?
要求 :
query getalllink{
allLinks(filter:{description_contains:"ab"}){
url,
postedBy {
id
,name
}
}
}
回复 :
{
"data": {
"allLinks": [
{
"url": "1a",
"postedBy": {
"id": "1",
"name": "1"
}
}
]
}
我提供了 TracingInstrumentation Bean。并且 bean 也被 GraphQLWebAutoConfiguration 拾取。
我尝试在 GraphQLWebAutoConfiguration 处调试并打断点,该工具已添加到 GraphQLServlet bean 中。
以下是有关我的示例项目的一些详细信息:
@SpringBootApplication
public class DemographqlApplication {
public static void main(String[] args) {
SpringApplication.run(DemographqlApplication.class, args);
}
@Bean
Instrumentation instrumentation() {
return new TracingInstrumentation();
}
}
resources/graphql/schema.graphqls
schema {
query: Query
}
type Query {
allLinks: [Link]
}
type Link {
id: ID!
url: String!
description: String
postedBy: User
}
type User {
id: ID!
name: String!
}
User
和的实体和存储库Link
解析器和查询解析器:
@Component
public class LinkResolver implements GraphQLResolver<Link> {
@Autowired
private final UserRepository userRepository;
LinkResolver(UserRepository userRepository) {
this.userRepository = userRepository;
}
public User postedBy(Link link) {
if (link.getUserId() == null) {
return null;
}
return userRepository.findOne(link.getUserId());
}
}
@Component
public class Query implements GraphQLQueryResolver {
private final LinkRepository linkRepository;
@Autowired
public Query(LinkRepository linkRepository) {
this.linkRepository = linkRepository;
}
public List<Link> allLinks() {
return linkRepository.findAll());
}
}
build.gradle
:
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile 'com.graphql-java:graphql-spring-boot-starter:3.10.0'
compile 'com.graphql-java:graphql-java-tools:4.3.0'
compile 'javax.xml.bind:jaxb-api:2.3.0'
compile 'com.h2database:h2'
// to embed GraphiQL tool
compile 'com.graphql-java:graphiql-spring-boot-starter:3.10.0'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
// Use MySQL Connector-J
compile 'mysql:mysql-connector-java'
}
谢谢你。