Skip to content

Commit

Permalink
Merge pull request #5869 from neo4j/deprecates-private
Browse files Browse the repository at this point in the history
Deprecates the private directive
  • Loading branch information
angrykoala authored Dec 6, 2024
2 parents bcafae7 + 34725f6 commit 3dafb57
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-knives-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Deprecates `@private` directive. The private directive was aimed to be used in conjunction with the OGM, which is no longer supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { ASTVisitor, ObjectTypeDefinitionNode } from "graphql";
import { privateDirective } from "../../../../graphql/directives";

export function WarnPrivateDeprecation() {
return function (): ASTVisitor {
let warningAlreadyIssued = false;

return {
ObjectTypeDefinition(objectTypeDefinition: ObjectTypeDefinitionNode) {
if (["Query", "Mutation", "Subscription"].includes(objectTypeDefinition.name.value)) {
return;
}
if (warningAlreadyIssued) {
return;
}
let hasPrivateDirective = false;
for (const field of objectTypeDefinition.fields || []) {
for (const directive of field.directives ?? []) {
if (directive.name.value === privateDirective.name) {
hasPrivateDirective = true;
}
}
}

if (hasPrivateDirective) {
console.warn(`Future library versions will not support @private directive.`);
warningAlreadyIssued = true;
}
},
};
};
}
2 changes: 2 additions & 0 deletions packages/graphql/src/schema/validation/validate-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
import { ValidFieldTypes } from "./custom-rules/valid-types/valid-field-types";
import { ValidObjectType } from "./custom-rules/valid-types/valid-object-type";
import { WarnIfAuthorizationFeatureDisabled } from "./custom-rules/warnings/authorization-feature-disabled";
import { WarnPrivateDeprecation } from "./custom-rules/warnings/deprecated-private";
import { WarnUniqueDeprecation } from "./custom-rules/warnings/deprecated-unique";
import { WarnIfAMaxLimitCanBeBypassedThroughInterface } from "./custom-rules/warnings/limit-max-can-be-bypassed";
import { WarnIfListOfListsFieldDefinition } from "./custom-rules/warnings/list-of-lists";
Expand Down Expand Up @@ -237,6 +238,7 @@ function runValidationRulesOnFilteredDocument({
WarnIfTypeIsNotMarkedAsNode(),
WarnIfQueryDirectionIsUsedWithDeprecatedValues,
WarnUniqueDeprecation(),
WarnPrivateDeprecation(),
],
schema
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Neo4jGraphQL } from "../../../src/classes";

describe("deprecated @unique warnings", () => {
let warn: jest.SpyInstance;

beforeEach(() => {
warn = jest.spyOn(console, "warn").mockImplementation(() => {});
});

afterEach(() => {
warn.mockReset();
});

test("warning on unique usage", async () => {
const typeDefs = /* GraphQL */ `
type User @node {
id: ID! @private
firstName: String!
}
type Movie @node {
id: ID! @private
title: String!
}
`;

const neoSchema = new Neo4jGraphQL({
typeDefs: typeDefs,
validate: true,
});
await neoSchema.getSchema();
expect(warn).toHaveBeenCalledWith("Future library versions will not support @private directive.");
});
});

0 comments on commit 3dafb57

Please sign in to comment.