Skip to content

Commit

Permalink
Merge pull request #5317 from neo4j/4534-authorization-validate-argum…
Browse files Browse the repository at this point in the history
…ent-should-also-handle-a-single-non-array-entry

Fix validate argument for non array inputs
  • Loading branch information
angrykoala authored Jul 5, 2024
2 parents d958b34 + f4c41fe commit af2e31d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-cycles-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fix non-array validate argument on authorization directive #4534
2 changes: 1 addition & 1 deletion packages/graphql/src/schema-model/generate-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("ConcreteEntity generation", () => {
},
},
]);
expect(authAnnotation?.validate).toBeUndefined();
expect(authAnnotation?.validate).toEqual([]);
});

test("authorization annotation is correct on User entity", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* limitations under the License.
*/
import type { DirectiveNode } from "graphql";
import { asArray } from "../../../utils/utils";
import type {
AuthorizationFilterRuleConstructor,
AuthorizationValidateRuleConstructor,
Expand All @@ -34,7 +35,7 @@ export function parseAuthorizationAnnotation(directive: DirectiveNode): Authoriz
validate?: Record<string, any>[];
};
const filterRules = filter?.map((rule) => new AuthorizationFilterRule(rule as AuthorizationFilterRuleConstructor));
const validateRules = validate?.map(
const validateRules = asArray(validate).map(
(rule) => new AuthorizationValidateRule(rule as AuthorizationValidateRuleConstructor)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ describe("Cypher Auth Allow", () => {
extend type User
@authorization(
validate: [
{
when: AFTER
operations: [CREATE, UPDATE, CREATE_RELATIONSHIP, DELETE_RELATIONSHIP]
where: { node: { id: "$jwt.sub" } }
}
]
validate: {
when: AFTER
operations: [CREATE, UPDATE, CREATE_RELATIONSHIP, DELETE_RELATIONSHIP]
where: { node: { id: "$jwt.sub" } }
}
)
extend type Post
Expand Down

0 comments on commit af2e31d

Please sign in to comment.