【发布时间】:2020-01-06 18:10:48
【问题描述】:
我正在使用 GraphQL、NodeJS 开发一个项目,我正在尝试创建一个名为 typedef.ts 的新文件,我想将其导入到我的 schema.ts 中,但由于某种原因我无法使其工作.
我得到的错误如下:
Error: typeDefs must be a string, array or schema AST, got object
到目前为止,我在 schema.ts 中尝试了以下更改:
import { makeExecutableSchema } from 'graphql-tools';
import { TypeDefs } from './typedefs/typedefs';
import { resolvers } from '../graphql/resolvers';
const typeDefs: Array<string> = TypeDefs; // <- Added this
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
logger: { log: e => console.log(e) },
});
typedef.ts:
import { types } from '../../graphql/types';
import { Types } from '../types/types';
const schemaDefinition = `
schema {
query : Query
mutation : Mutation
}
`;
export const TypeDefs = {
schemaDefinition,
// Card Type Def
cardDef: [Types.cardTypes.query, Types.cardTypes.mutation],
// User Type Def
userDef: [Types.userTypes.query, Types.userTypes.mutation],
...types,
};
请向我解释如何解决此问题,因为我找不到解决方案。
【问题讨论】: