首页 > 解决方案 > 使用graphql java kickstart的spring boot中的联合类型错误

问题描述

我在 graphql 中的 union 有问题,我尝试用 graphql 制作教程,但我遇到了一个错误

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.coxautodev.graphql.tools.UnionTypeResolver.<init>(DictionaryTypeResolver.kt:41)

The following method did not exist:

    'java.lang.String graphql.schema.GraphQLOutputType.getName()'

这是我在 graphqls 中定义的联合

type Talk {
    id : ID!
    title : String
    description : String
    speakers : [ Speaker ]
}

type Speaker {
    id : ID!
    name : String
    twitter : String
}

union All = Speaker | Talk

type Query {
    allAll : [All]
}

这是我的方法 allAll 的解析器

@RequiredArgsConstructor
public class MemberQueryResolver implements GraphQLQueryResolver {

    private final SpeakerService speakerService;
    private final TalkService talkService;

    public List<Object> allAll() {
        var list = new ArrayList<Object>();
        list.addAll(speakerService.findAll());
        list.addAll(talkService.findAll());
        return list;
    }
}

这是我的配置模式方法

private GraphQLSchema buildSchema(TalkService talkService, AttendeeService attendeeService,
                                      SpeakerService speakerService) {
        return SchemaParser
                .newParser()
                .file("graphql/schema.graphqls")
                .resolvers(
                        new MemberQueryResolver(speakerService, talkService)
                )
                .build()
                .makeExecutableSchema();
    }

当我删除解析器时,我收到错误,allAll 映射的方法不存在,但是当我使用此方法注册解析器时,spring 服务器崩溃并出现上述错误。有没有人尝试用 java kickstart 做联合类型并且可以告诉我问题或我的错误?

标签: javaspring-bootgraphqlgraphql-java

解决方案


推荐阅读