【问题标题】:GraphQL - Union Types giving the error no class could be found for that type nameGraphQL - 联合类型给出错误 no class could be found for that type name
【发布时间】:2020-05-04 02:05:37
【问题描述】:

在我的 GraphQL 架构文件中,我尝试添加一个联合类型,如下所示:

type CoOverrides {
    coId: String
    type: String
}

type SoOverrides {
    soId: String
    freeInterval: String
}

union CoOrSoOverrides = CoOverrides | SoOverrides

然后我将它分配给我的类型,如下所示:

type Campaign {
    id: ID!
    title: String
    overrides: [CoOrSoOverrides]
}

但是在启动 graphql 服务器时,我不断收到错误消息:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory method 'schemaParser' threw exception; 
nested exception is com.coxautodev.graphql.tools.SchemaClassScannerError: 
Object type 'CoOverrides' is a member of a known union, but no class could be found for that type name.  Please pass a class for type 'CoOverrides' in the parser's dictionary.

这到底是什么以及如何将这个类添加到解析器的字典中?

任何帮助表示赞赏。

谢谢。

【问题讨论】:

    标签: graphql graphql-schema


    【解决方案1】:

    如错误消息中所示 - 将 CoOverrides 类传递给字典。

    @Configuration
    public class SchemaParserConfig {
    
        @Bean
        public SchemaParserDictionary schemaParserDictionary() {
            return new SchemaParserDictionary()
                    .add(CoOverrides.class);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多