Cannot read property 'getQueryType' of undefined in NodeJS and graphql-tools - node.js

I'm new to NodeJS and started fixing some bugs. While starting node js app Cannot read property 'getQueryType' of undefined. The app is BFF for backend graphql services.
I'm not sure how to debug this.
Logs
🕸️ - GetMesh: Getting subschemas from source handlers
🕸️ - WorkspaceManager: Generating the schema
🕸️ - WorkspaceManager: The schema has been generated successfully
🕸️ - WorkspaceManager: Analyzing transforms
🕸️ - GetMesh: Schemas have been generated by the source handlers
🕸️ - GetMesh: Merging schemas using the defined merging strategy.
Stack Error : TypeError: Cannot read property 'getQueryType' of undefined
at getRootTypeMap (/app/node_modules/#graphql-tools/utils/index.js:685:30)
at Object.memoized [as getRootTypeMap] (/app/node_modules/#graphql-tools/utils/index.js:491:30)
at generateProxyingResolvers (/app/node_modules/#graphql-tools/wrap/index.js:15:31)
at Object.wrapSchema (/app/node_modules/#graphql-tools/wrap/index.js:80:31)
at BareMerger.handleSingleSource (/app/node_modules/#graphql-mesh/merger-bare/index.js:28:29)
at BareMerger.getUnifiedSchema (/app/node_modules/#graphql-mesh/merger-bare/index.js:69:25)
at getMesh (/app/node_modules/#graphql-mesh/runtime/index.js:114:46)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async MeshLoader.loadMesh (/app/runtime/mesh/mesh-loader.js:167:30)
at async initializeApp (/app/runtime/app.js:24:18).
Let me know, if more information is required to start with.

Related

WARNING! Error adding current blueprint templates as alternative for JHipster templates

I am trying to make a JHipster blueprint. Whenever I try to generate a project with it, I have warnings like
DEBUG! Found blueprint generator-jhipster-QuestionURL and server with namespace jhipster-QuestionURL:server
WARNING! Error adding current blueprint templates as alternative for JHipster templates.
Error: The Namespace jhipster-QuestionURL:server may not be correct. Please check your configuration and ensure your blueprint folder start with "generator-". Detail: Error: Error parsing namespace jhipster-QuestionURL:server
at module.exports.jhipsterTemplatePath (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base.js:187:13)
at new JHipsterBaseBlueprintGenerator (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base-blueprint.js:68:49)
at new JHipsterServerGenerator (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/server/index.js:75:5)
at new module.exports (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/generators/server/index.js:9:9)
at Environment.instantiate (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:801:23)
at Environment.create (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:773:17)
at JHipsterServerGenerator.composeWith (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1326:42)
at JHipsterServerGenerator._composeBlueprint (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:516:43)
at async JHipsterServerGenerator.composeWithBlueprints (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:413:34)
at async JHipsterServerGenerator._postConstruct (/usr/local/lib/node_modules/generator-jhipster/generators/server/index.js:96:7)
info Using blueprint generator-jhipster-QuestionURL for server subgenerator
showing up for each sub-generators I'm overriding. These warnings don't interrupt the questions asked by JHipster, but it prevents JHipster to generate the project in the end. When I finish answering all questions, I have this error message
ERROR! Template file src/main/docker/jib/entrypoint.sh was not found at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/generators/server/templates
Error: Template file src/main/docker/jib/entrypoint.sh was not found at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/generators/server/templates
at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base.js:2307:25
at Array.map (<anonymous>)
at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base.js:2237:42
at Array.map (<anonymous>)
at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base.js:2234:29
at Array.map (<anonymous>)
at module.exports.writeFilesToDisk (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/generator-base.js:2233:45)
at module.exports.writeFiles (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-QuestionURL2/node_modules/generator-jhipster/generators/server/files.js:1929:19)
at Object.<anonymous> (/home/dev/node_modules/yeoman-generator/lib/index.js:1097:23)
at /home/dev/node_modules/run-async/index.js:49:25
I am not familiar with namespaces so I can't pinpoint the problem. Does anyone know what is causing this and how to solve it?

NodeJS Bull queue.add stringify data causing errors

I am trying something like:
queue.add('queue', {
someId: '123',
service: this.service, // a service injected into the class where queue.add is present
}, { // other opts });
I get the error:
(node:94191) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at Job.toData (<project>/node_modules/bull/lib/job.js:192:20)
at addJob (<project>/node_modules/bull/lib/job.js:80:23)
at queue.isReady.then (<project>/node_modules/bull/lib/job.js:94:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:94191) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
which I believe is coming from
https://github.com/OptimalBits/bull/blob/develop/lib/job.js#L190-L200 .
Seems like the default is to try and stringify the entire job object, including the data field. So it complains on data fields provided that cannot be fully stringified. Is there no way around this? Is there no way to add a job to a queue with non-stringifiable custom data fields?
The reason I am injecting the service object instance into the job is because I am using a separate process in nestjs and there is no dependency injection available. I need access to that service in order to carry out certain DB operations from within the process. I don't want to create a separate DB connection every time a process runs.
Any help would be appreciated, thank you.
EDIT: I think my assumption here is incorrect. Redis itself cannot store non-stringified values.
Seems like the default is to try and stringify the entire job object, including the data field. So it complains on data fields provided that cannot be fully stringified. Is there no way around this?
You can exclude properties, but that's probably not what you want (the service property would be ignored).
The reason I am injecting the service object instance into the job is because I am using a separate process in nestjs and there is no dependency injection available
What about sending an id that matches the service? Something like this.service.id
I need access to that service in order to carry out certain DB operations from within the process. I don't want to create a separate DB connection every time a process runs
Maybe your service could expose an API of some sort that your workers could consume, so that all the db communication still occurs at service level?

problem running simple demo example google-maps-services-js with Node

I have a problem running this simple demo example for google-maps-service with Node:
https://github.com/jpoehnelt/google-maps-services-js-demo
I am not sure what I am missing. When I run npm start, I get this error:
TypeError: Cannot read property 'elevation' of undefined
at D:\node_practice\google-maps-services-js-demo\index.js:14:35
at processTicksAndRejections (internal/process/task_queues.js:97:5)
I am using nvm and my node version is 13.9.0. I tried it on two different machines (one windows with above node version, one ubuntu) and both got the same error.
it seems the response coming back is empty. your r.data is empty, which means results[0] is undefined, so is the reason you are getting Cannot read property 'elevation' of undefined.
Below is the actual exception coming back from the APIs
"You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account"
Get the instruction of getting an API key from here https://developers.google.com/maps/documentation/directions/get-api-key
and use the same with your code.

NodeJS/Express: ECONNRESET when doing multiples requests using Sequelize/Epilogue

I'm building a webapp using the following the architecture:
a postgresql database (called DB),
a NodeJS service (called DBService) using Sequelize to manipulate the DB and Epilogue to expose a REST interface via Express,
a NodeJS service called Backend serving as a backend and using DBService threw REST calls
an AngularJS website called Frontend using Backend
Here are the version I'm using:
PostgreSQL 9.3
Sequelize 2.0.4
Epilogue 0.5.2
Express 4.13.3
My DB schema is quite complex containing 36 tables and some of them contains few hundreds of records. The DB is not meant to write data very often, but mostly to read them.
But recently I created a script in Backend to make a complete check up of datas contained inside the DB: basically this script retrieve all datas of all tables and do some basic checks on datas. Currently the script only does reading on database.
In order to achieve my script I had to remove the pagination limit of Epilogue by using the option pagination: false (see https://github.com/dchester/epilogue#pagination).
But now when I launch my script I randomly obtained that kind of error:
The request failed when trying to retrieve a uniquely associated objects with URL:http://localhost:3000/CallTypes/178/RendererThemes.
Code : -1
Message : Error: connect ECONNRESET 127.0.0.1:3000
The error randomly appears during the script execution: then it's not always this URL which is returned, and even not always the same tables or relations. The error message before code is a custom message returned by Backend.
The URL is a reference to the DBService but I don't see any error in it, even using logging: console.log in Sequelize and DEBUG=express:* to see what happens in Express.
I tried to put some setTimeout in my Backend script to slow it, without real change. I also tried to manipulate different values like PostgreSQL max_connections limit (I set the limit to 1000 connections), or Sequelize maxConcurrentQueries and pool values, but without success yet.
I did not find where I can customize the pool connection of Express, maybe it should do the trick.
I assume that the error comes from DBService, from the Express configuration or somewhere in the configuration of the DB (either in Sequelize/Epilogue or even in the postgreSQL server itself), but as I did not see any error in any log I'm not sure.
Any idea to help me solve it?
EDIT
After further investigation I may have found the answer which is very similar to How to avoid a NodeJS ECONNRESET error?
: I'm using my own object RestClient to do my http request and this object was built as a singleton with this method:
var NodeRestClient : any = require('node-rest-client').Client;
...
static getClient() {
if(RestClient.client == null) {
RestClient.client = new NodeRestClient();
}
return RestClient.client;
}
Then I was always using the same object to do all my requests and when the process was too fast, it created collisions... So I just removed the test if(RestClient.client == null) and for now it seems to work.
If there is a better way to manage that, by closing request or managing a pool feel free to contribute :)

Socket.IO: Cannot read property 'query' of undefined of handshake data

In our NodeJS project we use socket.io v0.9.11 (planning to update at least this year) + RedisStore. From time to time we have such error that crashes Node process:
TypeError: Cannot read property 'query' of undefined
This happens at place when code tries accessing socket.handshake.query data for logging.
Maybe someone knows about this issue or experienced similar thing. What internal socket.io processes may set socket.handshake to undefined? I don't see any statements that may delete or set this to undefined in my code.

Resources