diff --git a/.changeset/many-jars-swim.md b/.changeset/many-jars-swim.md new file mode 100644 index 0000000000..b68856de2c --- /dev/null +++ b/.changeset/many-jars-swim.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": patch +--- + +Fix error message for wrong `requireAuthentication` argument on `@authorization` directive diff --git a/packages/graphql/src/schema/validation/utils/map-error.test.ts b/packages/graphql/src/schema/validation/utils/map-error.test.ts index fb66857682..9693beaa97 100644 --- a/packages/graphql/src/schema/validation/utils/map-error.test.ts +++ b/packages/graphql/src/schema/validation/utils/map-error.test.ts @@ -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", () => { diff --git a/packages/graphql/src/schema/validation/utils/map-error.ts b/packages/graphql/src/schema/validation/utils/map-error.ts index d82bbb1857..ca1c9cc040 100644 --- a/packages/graphql/src/schema/validation/utils/map-error.ts +++ b/packages/graphql/src/schema/validation/utils/map-error.ts @@ -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\\?".+?\\?")/; // 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)(:.+)/;