【问题标题】:Spring Boot with GraphQL - schema issue带有 GraphQL 的 Spring Boot - 架构问题
【发布时间】:2020-02-22 13:42:31
【问题描述】:

我正在使用 GraphQL 和 Spring Boot,但我在这个问题上停留了一段时间。

首先,这是我的 build.gradle:

...
compile 'com.graphql-java-kickstart:graphql-spring-boot-starter:5.10.0'
compile group: 'com.graphql-java', name: 'graphql-java-tools', version: '5.2.4'
runtime 'com.graphql-java-kickstart:graphiql-spring-boot-starter:5.10.0'
...

我有一个实体,比如说 - Dog、一个存储库、服务、Mutator 和一个查询。在 /resources 我有 dogs.graphqls 与那里的架构。

但由于某种原因,我无法启动应用程序。错误消息显示:No graphql schema files found on classpath with location pattern '**/*.graphqls'。当我删除对com.graphql-java-kickstart:graphql-spring-boot-starter 的依赖时,它会启动,但找不到架构。

有什么想法吗?

【问题讨论】:

    标签: java spring spring-boot graphql


    【解决方案1】:

    在 pom.xml 中包含以下代码:

    <resources>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.properties</include>
            <include>**/*.graphqls</include>
        </includes>
    </resource>
    

    【讨论】:

      【解决方案2】:

      我有一个 GraphQL spring-boot 项目,我发现有 2 个不同之处:

      • 我的架构在 resources/graphql - 可能没关系
      • 其他一些依赖项 - 我记得使用这些依赖项来解决与此类似的问题

      看看 - https://github.com/xShadov/code-hellven/blob/master/core/api/pom.xml - 尝试使用类似的依赖项(不确定它如何转换为 gradle):

      <graphql.version>5.4.1</graphql.version>
      <graphql-datetime-spring-boot-starter.version>1.4.0</graphql-datetime-spring-boot-starter.version>
      
      <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>
      </dependency>
      <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>voyager-spring-boot-starter</artifactId>
        <version>${graphql.version}</version>
      </dependency>
      <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>graphql-java-tools</artifactId>
        <version>${graphql.version}</version>
      </dependency>
      <dependency>
        <groupId>com.zhokhov.graphql</groupId>
        <artifactId>graphql-datetime-spring-boot-starter</artifactId>
        <version>${graphql-datetime-spring-boot-starter.version}</version>
      </dependency>
      

      【讨论】:

        【解决方案3】:

        我用这些更改了 kickstarter 依赖项:

        compile group: 'com.graphql-java', name: 'graphql-spring-boot-starter', version: '5.0.2'
        compile group: 'com.graphql-java', name: 'graphql-java-tools', version: '5.2.4'
        compile group: 'com.graphql-java', name: 'graphiql-spring-boot-starter', version: '3.0.3'
        

        :|

        【讨论】:

          猜你喜欢
          • 2019-07-20
          • 1970-01-01
          • 1970-01-01
          • 2020-11-25
          • 2018-12-19
          • 2020-11-25
          • 2020-12-16
          • 1970-01-01
          • 2021-12-21
          相关资源
          最近更新 更多