GraphQL:无法匹配类型定义(TypeName{name='Long'})



我刚刚使用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;
GraphQL规范仅将Int、Float、String、Boolean和ID指定为基元类型(也称为"标量"(。但是,它确实允许扩展这组标量类型。您正在使用的GraphQL规范的实现GraphQLJava默认情况下不提供Long标量类型。您可以设置自己的,但在这种情况下,我认为使用graphql-java扩展标量包会更容易。这很容易设置。注意,它提供了表示java.lang.LongGraphQLLong标量类型def。如果您不想使用";GraphQLLong";对于这种类型,您可以将其别名为:
GraphQLScalarType longScalar =
ExtendedScalars.newAliasedScalar('Long')
.aliasedScalar(ExtendedScalars.GraphQLLong)
.build() 

请参阅graphql-java扩展标量的文档,并深入研究源代码,了解它们是如何设置标量的。

相关内容

最新更新