1

I am setting up a new project using graphql-modules and am trying to get some tests running on my first module.

My module is pretty simple

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],
});

And my schema is very simple

type Mutation {
    register(email: String!, password: String!): User
}

type Query {
    user(id: ID!): User
}

type User {
    id: ID
    email: String!
    password: String!
}

Everything works perfectly when I run a local instance using ts-node, however when I try to run these tests

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");
  });
});

Suddenly my schema is invalid, that test is straight out of the graphql-modules docs and I have made sure to include a couple of extra modules which make my app run correctly.

The error that I am getting is:

          - #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;
         |             ^

I have spent a bit of time removing pieces but nothing I do seems to help and all google results seem to be irrelevant.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Rick
  • 1,063
  • 8
  • 26

0 Answers0