EasyGraphQL / easygraphql-tester

Test GraphQL queries, mutations and schemas on an easy way! 🚀
https://easygraphql.com/docs/easygraphql-tester/overview
MIT License
313 stars 34 forks source link

Error when combined with gql schema #105

Closed kottkrig closed 5 years ago

kottkrig commented 5 years ago

I'm trying to use EasyGraphQLTester with apollo and the gql template literals. I'm new to the GraphQL-world so combining apollo with EasyGraphQLTester might not even be valid use-case. But if it should be possible it would be nice to have an example of a correct setup in the readme.

I'm getting the following error:

    TypeError: Cannot read property 'types' of undefined

      14 | 
      15 |   beforeEach(() => {
    > 16 |     tester = new EasyGraphQLTester(typeDefs);
         |              ^
      17 |   });
      18 | 
      19 |   test("validate schema", () => {

      at buildClientSchema (node_modules/graphql/utilities/buildClientSchema.js:57:61)
      at buildGraphQLSchema (node_modules/easygraphql-tester/utils/buildGraphQLSchema.js:15:28)
      at new Tester (node_modules/easygraphql-tester/lib/tester.js:27:22)
      at Object.beforeEach (src/schema.test.js:16:14)

And this is the code:

const EasyGraphQLTester = require("easygraphql-tester");
const { gql } = require("apollo-server-express");

const typeDefs = gql`
  type Query {
    name: String!
  }
`;

describe("schema validation", () => {
  let tester;

  beforeEach(() => {
    tester = new EasyGraphQLTester(typeDefs);
  });

  test("validate schema", () => {
    const validQuery = `
          {
            name
          }
        `;

    tester.test(true, validQuery);
  });
});
estrada9166 commented 5 years ago

Thank you for creating this issue, I'm going to work to support gql, but in the meantime, you can try:

const typeDefs = `
  type Query {
    name: String!
  }
`;

And it'll work

estrada9166 commented 5 years ago

This is fixed on v5.1.5. If it's not working as expected we can open this issue again 🙂