Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validate argument for non array inputs #5317

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading