我正在使用 graphql-modules 建立一个新项目,并试图在我的第一个模块上运行一些测试。
我的模块很简单
import { GraphQLModule } from "@graphql-modules/core";
import * as typeDefs from "./user.schema.graphql";
import { UserResolvers } from "./user.resolvers";
import { UserProvider } from "./user.provider";
export const UserModule = new GraphQLModule({
typeDefs,
resolvers: UserResolvers,
providers: [UserProvider],
});
我的架构很简单
type Mutation {
register(email: String!, password: String!): User
}
type Query {
user(id: ID!): User
}
type User {
id: ID
email: String!
password: String!
}
当我使用 ts-node 运行本地实例时,一切正常,但是当我尝试运行这些测试时
import { execute } from "graphql";
import { gql } from "apollo-server";
import { App } from "./app";
describe("UserModule", () => {
it("FieldResolver of Query: userById", async () => {
const { schema } = App;
const result = await execute({
schema,
document: gql`
query {
user(id: "ANOTHERID") {
id
email
}
}
`,
});
expect(result.errors).toBeFalsy();
expect(result.data["userById"]["id"]).toBe("ANOTHERID");
expect(result.data["userById"]["email"]).toBe("email@email.com");
});
});
突然我的架构无效,该测试直接来自 graphql-modules 文档,我确保包含几个额外的模块,使我的应用程序正常运行。
我得到的错误是:
- #Module #D:\projects\hello-world\server\src\modules\app.ts_6292583185464227 doesn't have a valid schema!
-- Cannot read property 'prev' of undefined
Possible solutions:
- Check syntax errors in typeDefs
- Make sure you import correct dependencies
5 | describe("UserModule", () => {
6 | it("FieldResolver of Query: userById", async () => {
> 7 | const { schema } = App;
| ^
我花了一些时间删除碎片,但我所做的似乎无济于事,所有谷歌搜索结果似乎都无关紧要。