Dulara Malindu
Dulara Malindu

Reputation: 1637

GraphQL response ERROR "URLSearchParams is not defined"

those are the dependencies I'm using

"dependencies": {
"express": "^4.16.3",
"express-graphql": "^0.6.12",
"graphql": "^0.13.2",
"lodash": "^4.17.10"

}

here is my schema.js file looks like

here is the code inside my server.js file

and I recieve this error enter image description here

Upvotes: 2

Views: 1261

Answers (2)

Dulara Malindu
Dulara Malindu

Reputation: 1637

lodash library find methods first parameter is the data source. so URLSearchParam is mistakenly typed. be careful about auto completions of some IDEs provide. so they may fill incorrect data as you type.

using a good JavaScript linter can point you that problem. I do recommend eslint.

in this situation the data source is the variable users so replacing URLSearchParam with users solved this problem.

Upvotes: 0

Endrigo Araujo
Endrigo Araujo

Reputation: 61

I was facing the same issue. Here's how I managed to fix it:

const { URLSearchParams } = require('url');
global.URLSearchParams = URLSearchParams;

Upvotes: 6

Related Questions