-
I am trying to use the new v4 method to alter response before sending it out to the client but i am struggling to understand where is the response data in the context variable. async willSendResponse({ response }) {
if (response.body.kind === "single" && "data" in response.body.singleResult )
console.log(response.body.singleResult.data)
} But Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I managed to solve by checking that response.body.singleResult.data contains other keys in addition to __schema. if (Object.keys(omit(response.body.singleResult.data, "__schema")).length > 0){
console.log(omit(response.body.singleResult.data, "__schema"))
// {"entities": [{"id":1}, ...]}
} |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I understand what you're trying to do and what you're seeing. It looks like you're trying to differentiate between introspection and non-introspection queries, based on your own answer? |
Beta Was this translation helpful? Give feedback.
-
I am trying to alter the response of the graphql api on the fly to automatically parse nested stringified json. Entitty {
.. fields
config: '{"field":"value","field2":"{\\"nested_stringifiedfield\\":3}"}' // stringified json with nested stringified json
} So i have to recursively explore the returned records to parse the deep nested data |
Beta Was this translation helpful? Give feedback.
I managed to solve by checking that response.body.singleResult.data contains other keys in addition to __schema.
Only at that point the
willSendResponse
response contains the final response.