- apollo-server Version:
"apollo-server-express": "^2.25.2",
- Operating System (or Browser):
not relevant
- Node Version:
FROM node:12.19.0-alpine3.10
- apollo-log Version:
^1.1.0
Using the mutate function modifies the original request to the server when modified. It therefore cannot fulfill its purpose as it is and can lead to nasty errors.
How Do We Reproduce?
Modify the request variables during requestDidStart in ApolloLogPlugin({mutate: (data: LogMutateData) => {...}} and see the server use the newly modified variables in its request.
Expected Behavior
The logging framework should be separate from the graphql server. The influence should be apollo -> apollo-log and not in any case apollo-log -> apollo.
Actual Behavior
Using the mutate function modifies the original request to the server when modified.
Suggested solution/workaround
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)
// mask password if part of the query
if (dataCopy.context.request.variables && dataCopy.context.request.variables.password) {
dataCopy.context.request.variables.password = '***'
}
// mask token at all times
dataCopy.context.context.token = '***'
return dataCopy
},
}),
]
WIth:
const copyInstance = (instance: any) => {
const data = Object.assign(
Object.create(Object.getPrototypeOf(instance)),
JSON.parse(JSON.stringify(instance)),
)
return data
}
This seems to work just fine - tho long terms test are not conducted yet.
Maybe the library can either document this problem or provide a solution which ensures performance (not cloning stuff on every request)
To ensure correct behaviour you can do the following:
console.log(data.context.request.variables)
console.log(dataCopy.context.request.variables)
References
This Problem occurred in: https://github.com/gradido/gradido
PR implementing suggested fix in our service: gradido/gradido#1477
Relevant files:
You can also use this project to reproduce the issue.
Feel free to get in touch on Discord: Dornhoeschen#4105
Further notices & Disclaimer
Please inform me if I am using your library wrongly leading to this error.
I believe this could also be the result of using apollo-server-express instead of apollo-server.
"apollo-server-express": "^2.25.2",not relevantFROM node:12.19.0-alpine3.10^1.1.0Using the
mutatefunction modifies the original request to the server when modified. It therefore cannot fulfill its purpose as it is and can lead to nasty errors.How Do We Reproduce?
Modify the request variables during
requestDidStartinApolloLogPlugin({mutate: (data: LogMutateData) => {...}}and see the server use the newly modified variables in its request.Expected Behavior
The logging framework should be separate from the graphql server. The influence should be
apollo -> apollo-logand not in any caseapollo-log -> apollo.Actual Behavior
Using the
mutatefunction modifies the original request to the server when modified.Suggested solution/workaround
WIth:
This seems to work just fine - tho long terms test are not conducted yet.
Maybe the library can either document this problem or provide a solution which ensures performance (not cloning stuff on every request)
To ensure correct behaviour you can do the following:
References
This Problem occurred in: https://github.com/gradido/gradido
PR implementing suggested fix in our service: gradido/gradido#1477
Relevant files:
You can also use this project to reproduce the issue.
Feel free to get in touch on Discord:
Dornhoeschen#4105Further notices & Disclaimer
Please inform me if I am using your library wrongly leading to this error.
I believe this could also be the result of using
apollo-server-expressinstead ofapollo-server.