gpt4 book ai didi

graphql - 如何在 Graphql-java 中实现自定义标量?

转载 作者:行者123 更新时间:2023-12-02 02:53:10 25 4
gpt4 key购买 nike

我是graphql的新手。我正在尝试实现自定义标量类型“电子邮件”。但低于错误。请你帮助我好吗?

by: com.coxautodev.graphql.tools.SchemaClassScannerError: Expected a user-defined GraphQL scalar type with name 'Email' but found none! at com.coxautodev.graphql.tools.SchemaClassScanner.validateAndCreateResult(SchemaClassScanner.kt:144) ~[graphql-java-tools-4.3.0.jar:na] at com.coxautodev.graphql.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:94) ~[graphql-java-tools-4.3.0.jar:na]



配置:
scalar Email

type Greeting {
id: ID!
message: String!
email:Email
}

type Query {
getGreeting(id: ID!): Greeting
}

type Mutation {
newGreeting(message: String!): Greeting!
}

版本信息:
springBootVersion = '1.5.8.RELEASE'

com.graphql-java:graphql-java:6.0')

com.graphql-java:graphql-java-tools:4.3.0')

com.graphql-java:graphql-java-servlet:4.7.0')

org.springframework.boot:spring-boot-starter-web')

com.graphql-java:graphql-spring-boot-starter:3.10.0')

com.graphql-java:graphiql-spring-boot-starter:3.10.0')

请帮忙...

最佳答案

尝试这个:

@Component
public class ScalarEMail extends GraphQLScalarType {
public ScalarEMail() {
super("Email", "Scalar Email", new Coercing() {
@Override
public Object serialize(Object o) throws CoercingSerializeException {
return ((Email) o).getEmail();
}

@Override
public Object parseValue(Object o) throws CoercingParseValueException {
return serialize(o);
}

@Override
public Object parseLiteral(Object o) throws CoercingParseLiteralException {
return Email.valueOf(((StringValue) o).getValue());
}
});
}
}

关于graphql - 如何在 Graphql-java 中实现自定义标量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51038079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com