use lodash clonedeep to copy objects

This commit is contained in:
Moriz Wahl 2022-02-14 12:57:24 +01:00
parent 760b7e2d01
commit a201cad0db
3 changed files with 16 additions and 9 deletions

View File

@ -18,6 +18,7 @@
}, },
"dependencies": { "dependencies": {
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/lodash.clonedeep": "^4.5.6",
"apollo-log": "^1.1.0", "apollo-log": "^1.1.0",
"apollo-server-express": "^2.25.2", "apollo-server-express": "^2.25.2",
"apollo-server-testing": "^2.25.2", "apollo-server-testing": "^2.25.2",
@ -29,6 +30,7 @@
"graphql": "^15.5.1", "graphql": "^15.5.1",
"jest": "^27.2.4", "jest": "^27.2.4",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lodash.clonedeep": "^4.5.0",
"module-alias": "^2.2.2", "module-alias": "^2.2.2",
"moment": "^2.29.1", "moment": "^2.29.1",
"mysql2": "^2.3.0", "mysql2": "^2.3.0",

View File

@ -2,14 +2,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ApolloLogPlugin, LogMutateData } from 'apollo-log' import { ApolloLogPlugin, LogMutateData } from 'apollo-log'
import cloneDeep from 'lodash.clonedeep'
const copyInstance = (instance: any) => {
const data = Object.assign(
Object.create(Object.getPrototypeOf(instance)),
JSON.parse(JSON.stringify(instance)),
)
return data
}
const plugins = [ const plugins = [
{ {
@ -32,7 +25,7 @@ const plugins = [
ApolloLogPlugin({ ApolloLogPlugin({
mutate: (data: LogMutateData) => { mutate: (data: LogMutateData) => {
// We need to deep clone the object in order to not modify the actual request // 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 // mask password if part of the query
if (dataCopy.context.request.variables && dataCopy.context.request.variables.password) { if (dataCopy.context.request.variables && dataCopy.context.request.variables.password) {

View File

@ -913,6 +913,18 @@
"@types/koa-compose" "*" "@types/koa-compose" "*"
"@types/node" "*" "@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": "@types/long@^4.0.0":
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9" resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"