-
Notifications
You must be signed in to change notification settings - Fork 168
✨ [RUM-13680] Add support for GraphQL GET requests with query params (APQ) #4125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
| graphQlConfig: GraphQlUrlOption | ||
| ): GraphQlMetadata | undefined { | ||
| const metadata = extractGraphQlRequestMetadata(request.requestBody, graphQlConfig.trackPayload) | ||
| const metadata = extractGraphQlRequestMetadata(request.requestBody, graphQlConfig.trackPayload, request.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: what about passing directly the full request to this method? instead of passing every needed request attributes
| if (requestBody && typeof requestBody === 'string') { | ||
| return extractFromBody(requestBody, trackPayload) | ||
| } | ||
| // Fallback for persisted queries | ||
| if (url) { | ||
| return extractFromUrlQueryParams(url, trackPayload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 suggestion: Instead of having the extract methods that call the build method internally, we could:
- rename the build method as sanitize since it seems to be the intent
- call the sanitize method from extractGraphQlRequestMetadata , so the specific extract methods would be more focused and the higher level method would manage the execution flow
- move the parseVariableParams to the sanitize function as well
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: 3fb3a92 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
| if (rawMetadata.variables) { | ||
| try { | ||
| // Parse to validate it's valid JSON, then keep the string | ||
| JSON.parse(rawMetadata.variables) | ||
| variables = rawMetadata.variables | ||
| } catch { | ||
| // Invalid JSON in variables, ignore | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: do we need to validate this? Maybe we can just trust that it is correctly encoded?
If we still want this validation, I suggest to:
- move it to
extractFromUrlQueryParams, since it's only useful in this case - maybe introduce a
tryJsonParsehelper, because we already have a few usages in this file. Ex:
function tryJsonParse<T = unknown>(text: string): T | undefined {
try { return JSON.parse(text) } catch {}
}Then
let graphqlBody: {
query?: string
operationName?: string
variables?: unknown
}
try {
graphqlBody = JSON.parse(requestBody)
} catch {
// Not valid JSON
return
}
if (!graphqlBody) {
return
}
// becomes
const graphqlBody = tryJsonParse<{
query?: string
operationName?: string
variables?: unknown
}>(requestBody)
if (!graphqlBody) {
return
}
Motivation
When using Apollo's Automatic Persisted Queries (APQ) with useGETForHashedQueries: true, GraphQL requests are sent as GET instead of POST. In this case, operationName, variables, and query are passed as URL query params instead of request body.
The extractGraphQlRequestMetadata function only inspects the request body, so it misses GraphQL metadata for GET requests in this particular context. As it was requested by a customer we could support it by parsing the url.
Changes
We could support it by parsing the url.
FR:#4063
Test instructions
Checklist