Json到GraphQLArgumetn对象的转换在图形查询中失败。
尝试将GraphQLInterface(带有自动发现、true和scanpackage)添加到上面的抽象类中,并将GraphQLtype类型设置为所有具体类。
我的图查询:
query contactsQuery($searchQuery : QueryInput) { contacts(searchQuery:$searchQuery){id}}
variables:{"searchQuery":{"bool":{"conditions":[{"must":{"matches":[{"singleFieldMatch":{"boost":null,"field":"firstname","value":"siddiq"}}],"bool":null}}]}})Java代码:
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME,include=JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({@type(value = Must.class, name="must"),@type(value = MustNot.class, name="mustNot")})
public abstract class Condition@JsonTypeInfo(use=JsonTypeInfo.Id.NAME,include=JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({@type(value = SingleFieldMatch.class, name="singleFieldMatch"),@type(value = MultiFieldMatch.class, name="multiFieldMatch")})
public abstract class Match@GraphQLQuery(name = "contacts")
public List getContacts(@GraphQLArgument(name ="searchQuery") Query query)它仍然会抛出错误,未知的字段错误等等。不确定哪个配置丢失了。使用AnnotatedResolvedBuilder构建GraphQLSchema,基本包配置了JacksonValueMappperFactory和单例服务。
发布于 2019-07-04 15:52:13
嗨,这可能是一个类似的问题,我最终得到了。
最初,我有以下几点
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type")
@GraphQLInterface(name = "AbstractClass", implementationAutoDiscovery = true)
public abstract class AbstractClass{使用下面的查询调用
addNewObject(object: {name: "soft2", id: "asdas"})要获得转换功能,我需要做以下更改
@JsonTypeInfo(use = Id.NAME, include = As.EXISTING_PROPERTY, property = "type")
@GraphQLInterface(name = "AbstractClass", implementationAutoDiscovery = true)
public abstract class AbstractClass{
private String type = this.getClass().getSimpleName();
/**
* @return the type
*/
@GraphQLQuery(name = "type", description = "The concrete type of the node. This should match the initialised class. E.g. \"Concrete\", \"DecafCoffee\"")
public String getType() {
return type;
}查询现在是
addNewConcreteObject(concrete: {name: "soft2", id: "asdas", type: "Concrete"})工作原因(我认为):在我的代码中使用Jackson转换器(ObjectMapper)从JSON转换为对象时。我之前注意到JSON需要知道要转换成什么类。因此,最初使用@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type")时,在将其写入字符串时会将type属性放入JSON中。
@JSON标记的包含可能会被SPQR获取,然后它似乎会使用Jackson转换器将您的查询转换为所需的对象。如果我是对的,这就是问题所在。由于查询不包含type,因此无法正确转换查询。此外,由于type属性不是对象的成员变量,而只是由ObjectMapper添加的,所以它不会被提取出来,因此它不是对象模式的一部分。因此,为了解决这个问题,我添加了type作为成员变量,它始终等于实际的类,然后更改我的JsonTypeInfo以查找现有的属性。
我很感谢这不是对你问题的直接回答(当然也不是一个很好的答案),但希望它能帮助你找到解决方案。
https://stackoverflow.com/questions/56797172
复制相似问题