Home > Enterprise >  TypeError in Easygraphql-tester
TypeError in Easygraphql-tester

Time:10-14

I'm new to Graphql and Typescript. My aim is to unit test Graphql resolvers with Easygraphql-tester. But I'm facing the following error.

TypeError: easygraphql_tester_1.EasyGraphQLTester is not a constructor

Following is my code:

import {EasyGraphQLTester} from "easygraphql-tester";

const schema = `
  type FamilyInfo {
    id: ID!
    isLocal: Boolean!
  }

  type Query {
    getFamilyInfoByIsLocal(isLocal: Boolean!): FamilyInfo
  }
`

const query: any = `
  query TEST($isLocal: Boolean!) {
    getFamilyInfoByIsLocal(isLocal: $isLocal) {
      id
      isLocal
    }
  }
`

function getFamilyInfoByIsLocal(__, args, ctx) {
  return {
    id: 1,
    isLocal: args.isLocal
  }
}

const resolvers: any = {
  Query: {
    getFamilyInfoByIsLocal    
  }
}

const tester = new EasyGraphQLTester(schema, resolvers);
tester.graphql(query, undefined, undefined, { isLocal: false})
.then((result: any) => console.log(result))
.catch((err: any) => console.log(err));

Any idea why I'm facing the constructor error?

CodePudding user response:

The problem lies is in way of importing. As there are no Type Definitions for this package. See Here

const EasyGraphQLTester = require('easygraphql-tester')
  • Related