【发布时间】:2021-11-09 11:22:54
【问题描述】:
我正在尝试使用从 GraphQL 文件加载的 TypeDefs 联合模式创建 Apollo-Server。但是,我收到此错误
Argument of type 'GraphQLSchema' is not assignable to parameter of type 'string | TemplateStringsArray'.
我相信我从文件中加载架构时使用了错误的函数loadSchema。
如何从文件中加载具有正确类型的架构以将其作为 TypeDef 提供给联合架构?
import { buildSubgraphSchema } from '@apollo/federation';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
import { loadSchema } from '@graphql-tools/load';
import { ApolloServer, gql } from 'apollo-server';
...
const typeDefs = await loadSchema(`${__dirname}/auth.graphql`, {
loaders: [new CodeFileLoader()],
});
const server = new ApolloServer({
schema: buildSubgraphSchema([
{
typeDefs: gql(typeDefs), // Error here `typeDefs`
resolvers,
}
]),
})
【问题讨论】:
标签: typescript graphql apollo-server graphql-tools