Skip to content

Commit

Permalink
fix: ordering of excluding keys for safe json
Browse files Browse the repository at this point in the history
  • Loading branch information
danstarns committed Sep 1, 2023
1 parent 3858dc9 commit 0a73b7c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
12 changes: 6 additions & 6 deletions graphql-otel.com/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-otel",
"version": "0.1.8",
"version": "0.1.9",
"description": "Opentelemetry GraphQL Schema Directives.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
15 changes: 7 additions & 8 deletions package/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ export const excludedKeys = [
"_result",
];

export function safeJson(object: any) {
const safeJSON = JSON.stringify(object || {}, (key, value) => {
export function safeJson(object: any = {}) {
const obj = { ...object };
excludedKeys.forEach((key) => {
delete obj[key];
});

return safeJsonStringify(obj, (key, value) => {
if (typeof value === "bigint") {
return value.toString();
}

if (excludedKeys.includes(key)) {
return undefined;
}

if (typeof value === "function") {
return "Function";
}

return value;
});

return safeJsonStringify(JSON.parse(safeJSON));
}

0 comments on commit 0a73b7c

Please sign in to comment.