简体   繁体   English

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

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

So according to the graphql-java-kickstart/graphql-java-tools a 'graphql' endpoint should become available when the dependency 'com.graphql-java-kickstart:graphql-spring-boot-starter' is added to the project and .graphqls schema files are scanned automatically.因此,根据 graphql-java-kickstart/graphql-java-tools,当将依赖项 'com.graphql-java-kickstart:graphql-spring-boot-starter' 添加到项目和 . graphqls 模式文件会自动扫描。

I have the following dependencies:我有以下依赖项:

...
        <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>

A schema definition:模式定义:

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

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

And a GraphQLQueryResolver for that:和一个 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);
}

According to the documentation:根据文档:

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.如果 graphql-spring-boot-starter 作为启动应用程序的依赖项添加并且应用程序中存在 GraphQLSchema bean,则可以在 /graphql 访问 servlet。 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 模式库时,也可以自动创建 GraphQL 模式。

The graphql-java-tools library should automatically create a schema, under these conditions:在以下条件下,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.所有 GraphQLResolver 和 GraphQLScalar bean 以及 SchemaParserDictionary 类型的 bean(用于提供所有其他类)都将用于创建 GraphQLSchema。 Any files on the classpath named *.graphqls will be used to provide the schema definition.名为 *.graphqls 的类路径上的任何文件都将用于提供模式定义。 See the Readme for more info.有关更多信息,请参阅自述文件。

I think I have everything it needs, but navigating to localhost:8080/graphql gives a 404. NB: localhost:8080/graphiql works, but it cannot load the schema.我想我拥有它需要的一切,但是导航到localhost:8080/graphql会给出 404。注意: localhost:8080/graphiql可以工作,但它无法加载架构。 It says:它说:

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

What am I missing?我错过了什么?

Apparently the application could not find any JpaRepositories, because the SpringBootApplication starter class was located in com.package.some.app while the repositories were in com.package.some.domain.repositories .显然应用程序找不到任何 JpaRepositories,因为 SpringBootApplication 启动类位于com.package.some.app而存储库位于com.package.some.domain.repositories The Component scanner was only scanning components with package com.package.som.app.组件扫描器只扫描带有com.package.som.app包的组件。 * *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM