Skip to content

Commit 3f228e9

Browse files
committed
fix: apply review fixes
1 parent de622e7 commit 3f228e9

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/abilityBuilder.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Span, trace } from "@opentelemetry/api";
1+
import type { Span } from "@opentelemetry/api";
22
import { relationsFilterToSQL } from "drizzle-orm";
33
import { debounce } from "es-toolkit";
44
import { lazy } from "./helpers/lazy";
@@ -556,9 +556,7 @@ export const createAbilityBuilder = <
556556
// in case we have a wildcard ability, skip the rest and return no filters at all
557557
if (filters === "unrestricted") {
558558
span?.setAttribute("abilities.status", "unrestricted");
559-
const r = transformToResponse();
560-
span?.end();
561-
return r;
559+
return transformToResponse();
562560
}
563561

564562
// if nothing has been allowed, block everything
@@ -571,9 +569,7 @@ export const createAbilityBuilder = <
571569
tableName.toString(),
572570
action,
573571
);
574-
const r = transformToResponse(blockEverythingFilter);
575-
span?.end();
576-
return r;
572+
return transformToResponse(blockEverythingFilter);
577573
}
578574

579575
// run all dynamic filters
@@ -590,9 +586,7 @@ export const createAbilityBuilder = <
590586
const result = func(userContext);
591587
// if one of the dynamic filters returns "allow", we want to allow everything
592588
if (result === "allow") {
593-
const r = transformToResponse();
594-
span?.end();
595-
return r;
589+
return transformToResponse();
596590
}
597591
// if nothing is returned, nothing is allowed by this filter
598592
if (result === undefined) continue;
@@ -627,9 +621,7 @@ export const createAbilityBuilder = <
627621
"blocked_everything",
628622
);
629623

630-
const r = transformToResponse(blockEverythingFilter);
631-
span?.end();
632-
return r;
624+
return transformToResponse(blockEverythingFilter);
633625
}
634626

635627
const mergedFilters =
@@ -640,15 +632,19 @@ export const createAbilityBuilder = <
640632
}, {});
641633

642634
span?.setAttribute("abilities.status", "applied");
643-
const r = transformToResponse(mergedFilters as any);
644-
span?.end();
645-
return r;
635+
return transformToResponse(mergedFilters as any);
646636
};
647637

648638
if (otel?.tracer) {
649639
return otel.tracer.startActiveSpan(
650640
`prepare_query_abilities_${action}`,
651-
assembleAbilities,
641+
(span) => {
642+
try {
643+
return assembleAbilities(span);
644+
} finally {
645+
span.end();
646+
}
647+
},
652648
);
653649
} else {
654650
return assembleAbilities();

lib/rumble.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export const db = drizzle(
241241
{
242242
attributes: {
243243
[AttributeNames.OPERATION_NAME]:
244-
options.operationName ?? undefined,
244+
options.operationName ?? "anonymous",
245245
// TODO
246246
// [AttributeNames.SOURCE]: print(options.document),
247247
},
@@ -317,20 +317,19 @@ export const db = drizzle(
317317
*/
318318
schemaBuilder,
319319
/**
320-
* Creates the native yoga instance. Can be used to run an actual HTTP server.
321-
*
322-
* @example
323-
*
324-
* ```ts
320+
* Creates the native yoga instance. Can be used to run an actual HTTP server.
321+
*
322+
* @example
325323
*
326-
import { createServer } from "node:http";
327-
* const server = createServer(createYoga());
328-
server.listen(3000, () => {
329-
console.info("Visit http://localhost:3000/graphql");
330-
});
331-
* ```
324+
* ```ts
325+
* import { createServer } from "node:http";
326+
* const server = createServer(createYoga());
327+
* server.listen(3000, () => {
328+
* console.info("Visit http://localhost:3000/graphql");
329+
* });
330+
* ```
332331
* https://the-guild.dev/graphql/yoga-server/docs#server
333-
*/
332+
*/
334333
createYoga,
335334
/**
336335
* Creates a sofa instance to offer a REST API.

lib/runtimeFiltersPlugin/runtimeFiltersPlugin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class RuntimeFiltersPlugin<
3939

4040
if (!filters || !Array.isArray(filters) || filters.length === 0) {
4141
span?.setAttribute("filters.status", "unrestricted");
42-
span?.end();
4342
// if no filter should be applied, just continue
4443
return resolver(parent, args, context, info);
4544
}
@@ -60,11 +59,9 @@ export class RuntimeFiltersPlugin<
6059

6160
// if the original value was an array, return an array
6261
if (Array.isArray(resolved)) {
63-
span?.end();
6462
return allowed;
6563
}
6664

67-
span?.end();
6865
// if the original value was a single value, return the first allowed
6966
// or null if not allowed
7067
return allowed[0] ?? null;
@@ -73,7 +70,13 @@ export class RuntimeFiltersPlugin<
7370
if (this.tracer) {
7471
return this.tracer.startActiveSpan(
7572
`apply_filters_${fieldConfig.name}`,
76-
runFilters,
73+
(span) => {
74+
try {
75+
return runFilters();
76+
} finally {
77+
span.end();
78+
}
79+
},
7780
);
7881
} else {
7982
return runFilters();

lib/types/rumbleInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type RumbleInput<
8181
}
8282
| undefined;
8383
/**
84-
* rumble can setup otel tracing if you want to. This will provide details of execution time and outcome to the provided tracer. See https://pothos-graphql.dev/docs/plugins/tracing#install for more information.
84+
* rumble can set up otel tracing if you want to. This will provide details of execution time and outcome to the provided tracer. See https://pothos-graphql.dev/docs/plugins/tracing#install for more information.
8585
*/
8686
otel?: {
8787
/**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@escape.tech/graphql-armor": "^3.2.0",
3939
"@graphql-yoga/plugin-disable-introspection": "^2.19.0",
4040
"@opentelemetry/api": "^1.9.0",
41+
"@opentelemetry/semantic-conventions": "^1.39.0",
4142
"@pothos/core": "^4.12.0",
4243
"@pothos/plugin-drizzle": "^0.17.0",
4344
"@pothos/plugin-smart-subscriptions": "^4.1.4",

0 commit comments

Comments
 (0)