Skip to content

Commit 9ab2001

Browse files
heiskrCopilot
andauthored
⚡️ Reduce article API response sizes for GraphQL and audit log pages (#60192)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4b29fb0 commit 9ab2001

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/article-api/templates/audit-logs-page.template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Each event below lists only its additional fields beyond these common fields.
2626
{% for event in events %}
2727
#### `{{ event.action }}`
2828

29-
{{ event.description }}
29+
{% if event.description and event.description != 'N/A' %}{{ event.description }}{% endif %}
3030

3131
{% if event.fields.size > 0 %}**Additional fields:** {% for field in event.fields %}`{{ field }}`{% unless forloop.last %}, {% endunless %}{% endfor %}{% endif %}
3232

src/article-api/templates/graphql-reference.template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Connection types with only the standard pagination fields (`edges`, `nodes`, `pa
6262

6363
### Fields for `{{ item.name }}`
6464

65-
{% for field in item.fields %}* `{{ field.name }}` ({{ field.type }}): {{ field.description }}{% if field.defaultValue %} Default: `{{ field.defaultValue }}`.{% endif %}{% if field.isDeprecated %} **Deprecated:** {{ field.deprecationReason }}{% endif %}{% if field.arguments.size > 0 %}
65+
{% for field in item.fields %}* `{{ field.name }}` ({{ field.type }}): {{ field.description }}{% if field.defaultValue %} Default: `{{ field.defaultValue }}`.{% endif %}{% if field.isDeprecated %} **Deprecated:** {{ field.deprecationReason }}{% endif %}{% if field.hasPaginationOnly %} _(Pagination: `after`, `before`, `first`, `last`)_{% elsif field.arguments.size > 0 %}
6666
{% for arg in field.arguments %} * `{{ arg.name }}` ({{ arg.type.name }}): {{ arg.description }}{% if arg.defaultValue %} Default: `{{ arg.defaultValue }}`.{% endif %}
6767
{% endfor %}{% endif %}
6868
{% endfor %}
@@ -73,7 +73,7 @@ Connection types with only the standard pagination fields (`edges`, `nodes`, `pa
7373

7474
### Fields for `{{ item.name }}`
7575

76-
{% for field in item.fields %}* `{{ field.name }}` ({{ field.type }}): {{ field.description }}{% if field.defaultValue %} Default: `{{ field.defaultValue }}`.{% endif %}{% if field.isDeprecated %} **Deprecated:** {{ field.deprecationReason }}{% endif %}{% if field.arguments.size > 0 %}
76+
{% for field in item.fields %}* `{{ field.name }}` ({{ field.type }}): {{ field.description }}{% if field.defaultValue %} Default: `{{ field.defaultValue }}`.{% endif %}{% if field.isDeprecated %} **Deprecated:** {{ field.deprecationReason }}{% endif %}{% if field.hasPaginationOnly %} _(Pagination: `after`, `before`, `first`, `last`)_{% elsif field.arguments.size > 0 %}
7777
{% for arg in field.arguments %} * `{{ arg.name }}` ({{ arg.type.name }}): {{ arg.description }}{% if arg.defaultValue %} Default: `{{ arg.defaultValue }}`.{% endif %}
7878
{% endfor %}{% endif %}
7979
{% endfor %}

src/article-api/transformers/graphql-reference-transformer.ts

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -278,31 +278,49 @@ export class GraphQLReferenceTransformer implements PageTransformer {
278278
}
279279
}
280280

281+
private static STANDARD_PAGINATION_ARGS = new Set(['after', 'before', 'first', 'last'])
282+
283+
/**
284+
* Check if a field has only the standard pagination arguments
285+
* (after, before, first, last) with no additional args.
286+
*/
287+
private hasOnlyStandardPaginationArgs(field: FieldT): boolean {
288+
if (!field.arguments || field.arguments.length !== 4) return false
289+
return field.arguments.every((arg) =>
290+
GraphQLReferenceTransformer.STANDARD_PAGINATION_ARGS.has(arg.name),
291+
)
292+
}
293+
281294
/**
282295
* Prepare fields for rendering
283296
*/
284297
private async prepareFields(fields: FieldT[]): Promise<Array<Record<string, unknown>>> {
285-
return fields.map((field) => ({
286-
name: field.name,
287-
type: field.type,
288-
href: field.href,
289-
description: field.description ? fastTextOnly(field.description) : '',
290-
defaultValue: field.defaultValue,
291-
isDeprecated: field.isDeprecated || false,
292-
deprecationReason: field.deprecationReason
293-
? fastTextOnly(field.deprecationReason)
294-
: undefined,
295-
arguments: field.arguments
296-
? field.arguments.map((arg) => ({
297-
name: arg.name,
298-
description: arg.description ? fastTextOnly(arg.description) : '',
299-
defaultValue: arg.defaultValue,
300-
type: {
301-
name: arg.type.name,
302-
href: arg.type.href,
303-
},
304-
}))
305-
: undefined,
306-
}))
298+
return fields.map((field) => {
299+
const hasPaginationOnly = this.hasOnlyStandardPaginationArgs(field)
300+
return {
301+
name: field.name,
302+
type: field.type,
303+
href: field.href,
304+
description: field.description ? fastTextOnly(field.description) : '',
305+
defaultValue: field.defaultValue,
306+
isDeprecated: field.isDeprecated || false,
307+
deprecationReason: field.deprecationReason
308+
? fastTextOnly(field.deprecationReason)
309+
: undefined,
310+
hasPaginationOnly,
311+
arguments:
312+
field.arguments && !hasPaginationOnly
313+
? field.arguments.map((arg) => ({
314+
name: arg.name,
315+
description: arg.description ? fastTextOnly(arg.description) : '',
316+
defaultValue: arg.defaultValue,
317+
type: {
318+
name: arg.type.name,
319+
href: arg.type.href,
320+
},
321+
}))
322+
: undefined,
323+
}
324+
})
307325
}
308326
}

0 commit comments

Comments
 (0)