graphql servlet 未使用 graphql-java-tools 启动(未找到架构文件?)

graphql servlet not started with graphql-java-tools (schema files not found?)

因此,根据 graphql-java-kickstart/graphql-java-tools,当将依赖项 'com.graphql-java-kickstart:graphql-spring-boot-starter' 添加到项目并自动扫描 .graphqls 模式文件时,'graphql' 端点应该可用。

我有以下依赖项:

...
        <spring-boot.version>2.3.3.RELEASE</spring-boot.version>
        <graphql.version>7.0.1</graphql.version>
        <graphql-java-tools.version>6.2.0</graphql-java-tools.version>

...

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <!-- graphql -->
        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphql-spring-boot-starter</artifactId>
            <version>${graphql.version}</version>
        </dependency>

        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphiql-spring-boot-starter</artifactId>
            <version>${graphql.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphql-java-tools</artifactId>
            <version>${graphql-java-tools.version}</version>
        </dependency>

架构定义:

in query.graphqls:
type Query {
    user(username: String!)
    users: [User]
}

in user.graphqls:
type User {
    userId: Number!
    username: String!
}

还有一个 GraphQLQueryResolver:

@Component
public class UserQueryResolver implements GraphQLQueryResolver {
    private final UserRepository userRepository;

    public UserQueryResolver(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public Iterable<User> users() {
        return this.userRepository.findAll();
    }

    public User user(String username) {
        return this.userRepository.findByUsername(username).orElseThrow();
    }
}

public interface UserRepository extends JpaRepository<User, Integer> {
    Optional<User> findByUsername(String username);
}

根据文档:

The servlet becomes accessible at /graphql if graphql-spring-boot-starter added as a dependency to a boot application and a GraphQLSchema bean is present in the application. Check out the simple example for the bare minimum required.

A GraphQL schema can also be automatically created when a supported graphql-java schema library is found on the classpath.

graphql-java-tools 库应该自动创建一个模式,在这些条件下:

All GraphQLResolver and GraphQLScalar beans, along with a bean of type SchemaParserDictionary (to provide all other classes), will be used to create a GraphQLSchema. Any files on the classpath named *.graphqls will be used to provide the schema definition. See the Readme for more info.

我想我拥有它需要的一切,但导航到 localhost:8080/graphql 会出现 404。 N.B.: localhost:8080/graphiql 有效,但无法加载架构。它说:

{
  "timestamp": "2020-09-15T12:22:21.748+00:00",
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/graphql"
}

我错过了什么?

显然应用程序找不到任何 JpaRepositories,因为 SpringBootApplication starter class 位于 com.package.some.app 而存储库位于 com.package.some.domain.repositories。组件扫描器仅扫描包 com.package.som.app.*

的组件