我刚刚使用Springboot学习graphql,并尝试了这个链接中的示例https://bezkoder.com/spring-boot-graphql-mysql-jpa/.现在我遇到了一个问题,无法理解它为什么会抛出这个错误。
有人能帮我指出我犯了什么错误吗?
错误:graphql.kickstart.tools.SchemaClassScannerError: Unable to match type definition (TypeName{name='Long'}) with java type (class java.lang.Long): No TypeDefinition for type name Long
author.graphqls
type Author {
id: ID!
name: String!
age: Int
}
# Root
type Query {
findAuthorById(id: Long): Author!
findAllAuthors: [Author]!
countAuthors: Long!
}
# Root
type Mutation {
createAuthor(name: String!, age: Int): Author!
}
Author.java
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "age")
private Integer age;
Long
标量类型。您可以设置自己的,但在这种情况下,我认为使用graphql-java扩展标量包会更容易。这很容易设置。注意,它提供了表示java.lang.Long
的GraphQLLong
标量类型def。如果您不想使用";GraphQLLong";对于这种类型,您可以将其别名为:
GraphQLScalarType longScalar =
ExtendedScalars.newAliasedScalar('Long')
.aliasedScalar(ExtendedScalars.GraphQLLong)
.build()
请参阅graphql-java扩展标量的文档,并深入研究源代码,了解它们是如何设置标量的。