diff --git a/package.json b/package.json index 344c5c96..73a2c22d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@graphql-tools/schema": "^10.0.0", "@snapshot-labs/keycard": "^0.4.0", "@snapshot-labs/snapshot-metrics": "^1.3.1", - "@snapshot-labs/snapshot-sentry": "^1.5.1", + "@snapshot-labs/snapshot-sentry": "^1.5.2", "@snapshot-labs/snapshot.js": "^0.8.0-beta.0", "bluebird": "^3.7.2", "connection-string": "^1.0.1", diff --git a/src/helpers/metrics.ts b/src/helpers/metrics.ts index 500a62d9..f3f50897 100644 --- a/src/helpers/metrics.ts +++ b/src/helpers/metrics.ts @@ -1,7 +1,7 @@ import init, { client } from '@snapshot-labs/snapshot-metrics'; import { capture } from '@snapshot-labs/snapshot-sentry'; import { Express, type Request, type Response } from 'express'; -import { parse } from 'graphql'; +import { GraphQLError, parse } from 'graphql'; import { spacesMetadata } from './spaces'; import { strategies } from './strategies'; import db from './mysql'; @@ -58,9 +58,13 @@ export default function initMetrics(app: Express) { if (query && operationName) { const definition = parse(query).definitions.find( // @ts-ignore - def => def.name.value === operationName + def => def.name?.value === operationName ); + if (!definition) { + return; + } + // @ts-ignore const types = definition.selectionSet.selections.map(sel => sel.name.value); @@ -71,7 +75,9 @@ export default function initMetrics(app: Express) { } } } catch (e: any) { - capture(e); + if (!(e instanceof GraphQLError)) { + capture(e); + } } }); } diff --git a/test/.env.test b/test/.env.test index 3f4db322..7346081a 100644 --- a/test/.env.test +++ b/test/.env.test @@ -1,2 +1,3 @@ HUB_DATABASE_URL=mysql://root:root@127.0.0.1:3306/hub_test SEQ_DATABASE_URL=mysql://root:root@127.0.0.1:3306/hub_test +NODE_ENV=test diff --git a/yarn.lock b/yarn.lock index 5f41659c..982d1776 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1315,10 +1315,10 @@ node-fetch "^2.7.0" prom-client "^14.2.0" -"@snapshot-labs/snapshot-sentry@^1.5.1": - version "1.5.1" - resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot-sentry/-/snapshot-sentry-1.5.1.tgz#c4b5da87a97f760d9327743f7748783aaef14d9a" - integrity sha512-2xM72Xqypr73x6iWP5kr9fsNDeygmbiflTLhKeahT5yjjpFaSyS2razha+qxjo6w+0rIwNQXXYnlcrju24K2iA== +"@snapshot-labs/snapshot-sentry@^1.5.2": + version "1.5.2" + resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot-sentry/-/snapshot-sentry-1.5.2.tgz#a8c48e6602e0f236ba582a6728381e542501fe2a" + integrity sha512-xDZKiXigmfBWimDQGQwh/1WoqcD2n23nQczjWe+ukkLSvqk3AMwWz0F2tnd/MLiiklSyHezfcAzsSVMxlZPsPA== dependencies: "@sentry/node" "^7.60.1"