-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5869 from neo4j/deprecates-private
Deprecates the private directive
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
51 changes: 51 additions & 0 deletions
51
packages/graphql/src/schema/validation/custom-rules/warnings/deprecated-private.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/graphql/tests/integration/migration-warnings/private-directive.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
}); | ||
}); |