Skip to content

Commit

Permalink
Feat/block suggestions plugin/remove extra chars (#730)
Browse files Browse the repository at this point in the history
* feat(packages/plugins/block-field-suggestions): remove trailing question mark from masked message

* feat(packages/plugins/block-field-suggestions): remove trailing whitespace from masked message

* style(test): format expected error message mapping

* chore(changeset): add major update for graphql-armor-block-field-suggestions

---------

Co-authored-by: nullswan <[email protected]>
  • Loading branch information
kallja and nullswan authored Nov 5, 2024
1 parent 638ee7d commit 0a26be4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-peas-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@escape.tech/graphql-armor-block-field-suggestions': major
---

feat(field-suggestion): remove extra chars
2 changes: 1 addition & 1 deletion examples/yoga/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('startup', () => {
expect(body.data?.books).toBeUndefined();
expect(body.errors).toBeDefined();
expect(body.errors?.map((e) => e.message)).toContain(
'Cannot query field "titlee" on type "Book". [Suggestion hidden]?',
'Cannot query field "titlee" on type "Book". [Suggestion hidden]',
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/block-field-suggestions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const blockFieldSuggestionsDefaultOptions: Required<BlockFieldSuggestionsOptions

const formatter = (error: GraphQLError, mask: string): GraphQLError => {
if (error instanceof GraphQLError) {
error.message = error.message.replace(/Did you mean ".+"/g, mask);
error.message = error.message.replace(/Did you mean ".+"\?/g, mask).trim();
}
return error as GraphQLError;
};
Expand Down
13 changes: 11 additions & 2 deletions packages/plugins/block-field-suggestions/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('global', () => {
assertSingleExecutionValue(result);
expect(result.errors).toBeDefined();
expect(result.errors?.map((error) => error.message)).toEqual([
'Cannot query field "titlee" on type "Book". [Suggestion hidden]?',
'Cannot query field "titlee" on type "Book". [Suggestion hidden]',
]);
});

Expand All @@ -95,7 +95,16 @@ describe('global', () => {
assertSingleExecutionValue(result);
expect(result.errors).toBeDefined();
expect(result.errors?.map((error) => error.message)).toEqual([
'Cannot query field "titlee" on type "Book". <[REDACTED]>?',
'Cannot query field "titlee" on type "Book". <[REDACTED]>',
]);
});

it('should use remove suggestion completely with emptry string for mask', async () => {
const testkit = createTestkit([blockFieldSuggestionsPlugin({ mask: '' })], schema);
const result = await testkit.execute(query);

assertSingleExecutionValue(result);
expect(result.errors).toBeDefined();
expect(result.errors?.map((error) => error.message)).toEqual(['Cannot query field "titlee" on type "Book".']);
});
});

0 comments on commit 0a26be4

Please sign in to comment.