Skip to content

Commit

Permalink
Merge pull request #5523 from MacondoExpress/add-node-migration-message
Browse files Browse the repository at this point in the history
Add a warning to instruct users about future requirements for marking Neoj4 nodes with the `@node` directive.
  • Loading branch information
MacondoExpress authored Sep 11, 2024
2 parents 7f35458 + 3f63a3f commit b4a3009
Show file tree
Hide file tree
Showing 896 changed files with 4,868 additions and 96,299 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-mayflies-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/introspector": minor
---

Added `@node` to the generated types.
5 changes: 5 additions & 0 deletions .changeset/tender-fans-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Add a warning to instruct users about future requirements for marking Neoj4 nodes with the `@node` directive.
2 changes: 1 addition & 1 deletion packages/graphql/src/classes/Neo4jGraphQL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Neo4jGraphQL", () => {
const errors: Error[] = await getErrorAsync(async () => {
schema = await new Neo4jGraphQL({
typeDefs:
'type User @authorization(filter: [{ where: { banana: { id: "$jwt.sub" } } }]) {id: ID}',
'type User @node @authorization(filter: [{ where: { banana: { id: "$jwt.sub" } } }]) {id: ID}',
}).getExecutableSchema();
});
expect(errors).toHaveLength(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/classes/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class Node extends GraphElement {
}

public getAllLabels(): string[] {
return this.nodeDirective?.labels || [this.name];
return this.nodeDirective?.labels.length ? this.nodeDirective.labels : [this.name];
}

public getGlobalIdField(): string {
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql/src/classes/Subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location @key(fields: "id") {
type Location @key(fields: "id") @node {
id: ID!
"The name of the location"
name: String!
Expand Down Expand Up @@ -61,7 +61,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location @key(fields: "id") {
type Location @key(fields: "id") @node {
id: ID!
"The name of the location"
name: String!
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location {
type Location @node {
id: ID!
"The name of the location"
name: String!
Expand All @@ -120,7 +120,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location {
type Location @node {
id: ID!
"The name of the location"
name: String!
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location @key(fields: "id") {
type Location @key(fields: "id") @node {
id: ID!
"The name of the location"
name: String!
Expand Down Expand Up @@ -216,7 +216,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location @key(fields: "id") {
type Location @key(fields: "id") @node {
id: ID!
"The name of the location"
name: String!
Expand Down Expand Up @@ -251,7 +251,7 @@ describe("Subgraph", () => {
location(id: ID!): Location
}
type Location @key(fields: "id") {
type Location @key(fields: "id") @node {
id: ID!
"The name of the location"
name: String!
Expand Down
42 changes: 22 additions & 20 deletions packages/graphql/src/schema-model/generate-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("ConcreteEntity generation", () => {
beforeAll(() => {
const typeDefs = gql`
type User
@node
@authorization(
validate: [
{ when: ["BEFORE"], where: { node: { id: { equals: "$jwt.sub" } } } }
Expand Down Expand Up @@ -168,7 +169,7 @@ describe("ConcreteEntity generation", () => {

beforeAll(() => {
const typeDefs = gql`
type User @subscriptionsAuthorization(filter: [{ where: { node: { id: "$jwt.sub" } } }]) {
type User @subscriptionsAuthorization(filter: [{ where: { node: { id: "$jwt.sub" } } }]) @node {
id: ID!
name: String!
}
Expand Down Expand Up @@ -242,11 +243,11 @@ describe("ComposeEntity generation", () => {
const typeDefs = gql`
union Tool = Screwdriver | Pencil
type Screwdriver {
type Screwdriver @node {
length: Int
}
type Pencil {
type Pencil @node {
colour: String
}
Expand All @@ -259,6 +260,7 @@ describe("ComposeEntity generation", () => {
}
type User implements Human & Animal
@node
@authorization(
validate: [
{ when: "BEFORE", where: { node: { id: { equals: "$jwt.sub" } } } }
Expand Down Expand Up @@ -326,7 +328,7 @@ describe("Relationship", () => {

beforeAll(() => {
const typeDefs = gql`
type User {
type User @node {
id: ID!
name: String!
accounts: [Account!]! @relationship(type: "HAS_ACCOUNT", properties: "hasAccount", direction: OUT)
Expand All @@ -351,26 +353,26 @@ describe("Relationship", () => {
union Show = Movie | TvShow
type Actor {
type Actor @node {
name: String
}
interface Production {
actors: [Actor!]! @declareRelationship
}
type Movie implements Production {
type Movie implements Production @node {
name: String!
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: OUT)
}
type TvShow implements Production {
type TvShow implements Production @node {
name: String!
episodes: Int
actors: [Actor!]! @relationship(type: "STARED_IN", direction: OUT)
}
type Account {
type Account @node {
id: ID!
username: String!
}
Expand Down Expand Up @@ -460,15 +462,15 @@ describe("ConcreteEntity Annotations & Attributes", () => {

beforeAll(() => {
const typeDefs = gql`
type User @query @mutation @subscription {
type User @query @mutation @subscription @node {
id: ID!
name: String! @selectable(onAggregate: true) @alias(property: "dbName")
defaultName: String! @default(value: "John")
age: Int! @populatedBy(callback: "thisCallback", operations: [CREATE])
accounts: [Account!]! @relationship(type: "HAS_ACCOUNT", direction: OUT)
}
type Account @subscription(events: [CREATED]) {
type Account @subscription(events: [CREATED]) @node {
id: ID!
accountName: String! @settable(onCreate: false)
}
Expand Down Expand Up @@ -537,7 +539,7 @@ describe("ConcreteEntity Annotations & Attributes", () => {
describe("Arguments", () => {
test("attribute argument scalar", () => {
const typeDefs = gql`
type User {
type User @node {
id: ID!
name(something: Int): String!
}
Expand All @@ -559,11 +561,11 @@ describe("ConcreteEntity Annotations & Attributes", () => {

test("attribute argument object", () => {
const typeDefs = gql`
type User {
type User @node {
id: ID!
favoritePet(from: [Animal]!): String!
}
type Animal {
type Animal @node {
sound: String
}
`;
Expand Down Expand Up @@ -592,14 +594,14 @@ describe("ComposeEntity Annotations & Attributes and Inheritance", () => {
aliasedProp: String! @alias(property: "dbName")
}
type Movie implements Production {
type Movie implements Production @node {
name: String!
year: Int
defaultName: String!
aliasedProp: String! @alias(property: "movieDbName")
}
type TvShow implements Production {
type TvShow implements Production @node {
name: String!
episodes: Int
year: Int @populatedBy(callback: "thisOtherCallback", operations: [CREATE])
Expand Down Expand Up @@ -670,7 +672,7 @@ describe("ComposeEntity Annotations & Attributes and Inheritance", () => {
aliasedProp: String! @alias(property: "movieDbName")
}
type TvShow implements TvProduction & Production {
type TvShow implements TvProduction & Production @node {
name: String!
episodes: Int
year: Int @populatedBy(callback: "thisOtherCallback", operations: [CREATE])
Expand Down Expand Up @@ -760,7 +762,7 @@ describe("GraphQL adapters", () => {

beforeAll(() => {
const typeDefs = gql`
type User {
type User @node {
id: ID!
name: String!
createdAt: DateTime
Expand All @@ -775,11 +777,11 @@ describe("GraphQL adapters", () => {
creationTime: DateTime!
}
type A {
type A @node {
id: ID
}
type B {
type B @node {
age: Int
}
Expand All @@ -790,7 +792,7 @@ describe("GraphQL adapters", () => {
DISABLED
}
type Account {
type Account @node {
status: Status
point: Point
points: [Point!]!
Expand Down
27 changes: 19 additions & 8 deletions packages/graphql/src/schema-model/parser/parse-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
Kind,
parse,
} from "graphql";
import { parseArguments, parseArgumentsFromUnknownDirective } from "./parse-arguments";
import { ScalarOrEnumType } from "../../graphql/directives/arguments/scalars/ScalarOrEnum";
import { parseArguments, parseArgumentsFromUnknownDirective } from "./parse-arguments";

describe("parseArguments", () => {
let testDirectiveDefinition: GraphQLDirective;
Expand Down Expand Up @@ -67,7 +67,7 @@ describe("parseArguments", () => {
test("should parse arguments", () => {
const typeDefs = `
type User {
type User @node {
name: String @testDirective(booleanArgument: false, intArgument: 2, floatArgument: 4.0, customScalar: "123", customListScalar: ["123"])
}
`;
Expand All @@ -87,12 +87,18 @@ describe("parseArguments", () => {

const args = parseArguments(testDirectiveDefinition, nameCoalesceUsage);

expect(args).toEqual({ booleanArgument: false, intArgument: 2, floatArgument: 4.0, customScalar: "123", customListScalar: ["123"] });
expect(args).toEqual({
booleanArgument: false,
intArgument: 2,
floatArgument: 4.0,
customScalar: "123",
customListScalar: ["123"],
});
});

test("should use default values", () => {
const typeDefs = `
type User {
type User @node {
name: String @testDirective(booleanArgument: false, intArgument: 2)
}
`;
Expand All @@ -112,12 +118,18 @@ describe("parseArguments", () => {

const args = parseArguments(testDirectiveDefinition, nameCoalesceUsage);

expect(args).toEqual({ booleanArgument: false, intArgument: 2, floatArgument: 3.0, customScalar: "test", customListScalar: ["test"] });
expect(args).toEqual({
booleanArgument: false,
intArgument: 2,
floatArgument: 3.0,
customScalar: "test",
customListScalar: ["test"],
});
});

test("parseArgumentsFromUnknownDirective", () => {
const typeDefs = `
type User {
type User @node {
name: String @testDirective(booleanArgument: false, intArgument: 2)
}
`;
Expand All @@ -137,7 +149,6 @@ describe("parseArguments", () => {

const args = parseArgumentsFromUnknownDirective(nameCoalesceUsage);

expect(args).toEqual({ booleanArgument: false, intArgument: 2});
expect(args).toEqual({ booleanArgument: false, intArgument: 2 });
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { parseValueNode } from "./parse-value-node";
describe("parseValueNode", () => {
test("should return a correct nested object", () => {
const typeDefs = `
type Movie @Auth(rules: [{ str: "string", int: 123, float: 12.3, bool: true }]) {
type Movie @Auth(rules: [{ str: "string", int: 123, float: 12.3, bool: true }]) @node {
name: String
}
`;
Expand Down
10 changes: 5 additions & 5 deletions packages/graphql/src/schema/get-field-type-meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import getFieldTypeMeta from "./get-field-type-meta";
describe("getFieldTypeMeta", () => {
test("should return NonNullType ListType type name", () => {
const typeDefs = `
type User {
type User @node {
name: [ABC]!
}
`;
Expand All @@ -45,7 +45,7 @@ describe("getFieldTypeMeta", () => {

test("should return NonNullType NamedType type name", () => {
const typeDefs = `
type User {
type User @node {
name: ABC!
}
`;
Expand All @@ -66,7 +66,7 @@ describe("getFieldTypeMeta", () => {

test("should return NamedType type name", () => {
const typeDefs = `
type User {
type User @node {
name: String
}
`;
Expand All @@ -87,7 +87,7 @@ describe("getFieldTypeMeta", () => {

test("should return ListType NamedType type name", () => {
const typeDefs = `
type User {
type User @node {
name: [ABC]
}
`;
Expand All @@ -108,7 +108,7 @@ describe("getFieldTypeMeta", () => {

test("should return ListType NonNullType type name", () => {
const typeDefs = `
type User {
type User @node {
name: [ABC!]
}
`;
Expand Down
Loading

0 comments on commit b4a3009

Please sign in to comment.