Skip to content

Commit

Permalink
Merge pull request #5904 from a-alle/fix-error-mapper-regex-dev
Browse files Browse the repository at this point in the history
Fix auth directives error mapping regex
  • Loading branch information
a-alle authored Dec 19, 2024
2 parents 03ac2b6 + 64d4da1 commit efad71f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/many-jars-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fix error message for wrong `requireAuthentication` argument on `@authorization` directive
25 changes: 25 additions & 0 deletions packages/graphql/src/schema/validation/utils/map-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,31 @@ describe("mapError", () => {
'Unknown argument "wrongFilter" on directive "@authorization". Did you mean "filter"?'
);
});

test("unknown argument requireAuthentication on directive", () => {
const errorOpts = {
nodes: [argumentNode],
extensions: undefined,
path: undefined,
source: undefined,
positions: undefined,
originalError: undefined,
};

// TODO: replace constructor to use errorOpts when dropping support for GraphQL15
const error = new GraphQLError(
'Unknown argument "requireAuthentication" on directive "@UserAuthorization".',
errorOpts.nodes,
errorOpts.source,
errorOpts.positions,
errorOpts.path,
errorOpts.originalError,
errorOpts.extensions
);
const mappedError = mapError(error);
expect(mappedError).toHaveProperty("message");
expect(mappedError.message).toBe('Unknown argument "requireAuthentication" on directive "@authorization".');
});
});

describe("UniqueDirectivesPerLocationRule", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/src/schema/validation/utils/map-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function mapCustomRuleError(error: GraphQLError): GraphQLError {
return error;
}

const RENAMED_DIRECTIVE_OR_TYPE = /(\s?"([^\s]*?([sS]ubscriptionsAuthorization|Authorization|Authentication)[^\s]*?)")/;
const RENAMED_DIRECTIVE_OR_TYPE =
/(\s?"((?!requireAuthentication)[^\s]*?([sS]ubscriptionsAuthorization|Authorization|Authentication)[^\s]*?)")/;
const WHERE_TYPE = /type(\s\\?".+?\\?")/; // <typename>Where / JwtPayloadWhere
const JWT_PAYLOAD_DUMMY_VALUE_ERROR =
/(?:(?:String)|(?:Int)|(?:Float)|(?:Boolean))(?: cannot represent a?\s?)(?:(?:non string)|(?:non-integer)|(?:non numeric)|(?:non boolean))(?: value)(:.+)/;
Expand Down

0 comments on commit efad71f

Please sign in to comment.