diff --git a/backend/package.json b/backend/package.json index 043dca11d..2e58d27a2 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,7 @@ }, "dependencies": { "@types/jest": "^27.0.2", + "@types/lodash.clonedeep": "^4.5.6", "apollo-log": "^1.1.0", "apollo-server-express": "^2.25.2", "apollo-server-testing": "^2.25.2", @@ -29,6 +30,7 @@ "graphql": "^15.5.1", "jest": "^27.2.4", "jsonwebtoken": "^8.5.1", + "lodash.clonedeep": "^4.5.0", "module-alias": "^2.2.2", "moment": "^2.29.1", "mysql2": "^2.3.0", diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index 4f3a15b90..049f63a08 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -2,14 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { ApolloLogPlugin, LogMutateData } from 'apollo-log' - -const copyInstance = (instance: any) => { - const data = Object.assign( - Object.create(Object.getPrototypeOf(instance)), - JSON.parse(JSON.stringify(instance)), - ) - return data -} +import cloneDeep from 'lodash.clonedeep' const plugins = [ { @@ -32,7 +25,7 @@ const plugins = [ ApolloLogPlugin({ mutate: (data: LogMutateData) => { // We need to deep clone the object in order to not modify the actual request - const dataCopy = copyInstance(data) + const dataCopy = cloneDeep(data) // mask password if part of the query if (dataCopy.context.request.variables && dataCopy.context.request.variables.password) { diff --git a/backend/yarn.lock b/backend/yarn.lock index 52cd0f751..6ef0d5701 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -913,6 +913,18 @@ "@types/koa-compose" "*" "@types/node" "*" +"@types/lodash.clonedeep@^4.5.6": + version "4.5.6" + resolved "https://registry.yarnpkg.com/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.6.tgz#3b6c40a0affe0799a2ce823b440a6cf33571d32b" + integrity sha512-cE1jYr2dEg1wBImvXlNtp0xDoS79rfEdGozQVgliDZj1uERH4k+rmEMTudP9b4VQ8O6nRb5gPqft0QzEQGMQgA== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.178" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8" + integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw== + "@types/long@^4.0.0": version "4.0.1" resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"