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

Migrate all the integration/issues tests to use the UniqueType utility. #4820

Merged
merged 5 commits into from
Mar 5, 2024
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
39 changes: 25 additions & 14 deletions packages/graphql/tests/integration/issues/1150.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { gql } from "graphql-tag";
import type { Driver } from "neo4j-driver";
import { Neo4jGraphQL } from "../../../src";
import { createBearerToken } from "../../utils/create-bearer-token";
import { UniqueType } from "../../utils/graphql-types";
import Neo4jHelper from "../neo4j";

describe("https://github.com/neo4j/graphql/issues/1150", () => {
Expand All @@ -31,45 +32,55 @@ describe("https://github.com/neo4j/graphql/issues/1150", () => {
let driver: Driver;
let neo4j: Neo4jHelper;

let Battery: UniqueType;
let CombustionEngine: UniqueType;
let Drive: UniqueType;
let DriveComposition: UniqueType;
MacondoExpress marked this conversation as resolved.
Show resolved Hide resolved

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();

Battery = new UniqueType("Battery");
CombustionEngine = new UniqueType("CombustionEngine");
Drive = new UniqueType("Drive");
DriveComposition = new UniqueType("DriveComposition");

const typeDefs = gql`
type JWTPayload @jwt {
roles: [String!]!
}

type Battery {
type ${Battery} {
id: ID! @unique
current: Boolean!
}

extend type Battery
extend type ${Battery}
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "admin" } } }])

type CombustionEngine {
type ${CombustionEngine} {
id: ID! @unique
current: Boolean!
}

type Drive {
type ${Drive} {
id: ID! @unique
current: Boolean!
driveCompositions: [DriveComposition!]!
driveCompositions: [${DriveComposition}!]!
@relationship(type: "CONSISTS_OF", properties: "RelationProps", direction: OUT)
}

union DriveComponent = Battery | CombustionEngine
union DriveComponent = ${Battery} | ${CombustionEngine}

type DriveComposition {
type ${DriveComposition} {
id: ID! @unique
current: Boolean!
driveComponent: [DriveComponent!]!
@relationship(type: "HAS", properties: "RelationProps", direction: OUT)
}

type RelationProps @relationshipProperties {
type RelationProps @relationshipProperties {
current: Boolean!
}
`;
Expand All @@ -92,26 +103,26 @@ describe("https://github.com/neo4j/graphql/issues/1150", () => {
test("should handle union types with auth and connection-where", async () => {
const query = /* GraphQL */ `
query getDrivesWithFilteredUnionType {
drives(where: { current: true }) {
${Drive.plural}(where: { current: true }) {
current
driveCompositionsConnection(where: { edge: { current: true } }) {
edges {
node {
driveComponentConnection(
where: {
Battery: { edge: { current: true } }
CombustionEngine: { edge: { current: true } }
${Battery}: { edge: { current: true } }
${CombustionEngine}: { edge: { current: true } }
}
) {
edges {
properties {
current
}
node {
... on Battery {
... on ${Battery} {
id
}
... on CombustionEngine {
... on ${CombustionEngine} {
id
}
}
Expand All @@ -133,6 +144,6 @@ describe("https://github.com/neo4j/graphql/issues/1150", () => {

expect(res.errors).toBeUndefined();

expect(res.data).toEqual({ drives: [] });
expect(res.data).toEqual({ [Drive.plural]: [] });
});
});
32 changes: 20 additions & 12 deletions packages/graphql/tests/integration/issues/1249.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,43 @@ import type { GraphQLSchema } from "graphql";
import { graphql } from "graphql";
import type { Driver } from "neo4j-driver";
import { Neo4jGraphQL } from "../../../src";
import { UniqueType } from "../../utils/graphql-types";
import Neo4jHelper from "../neo4j";

describe("https://github.com/neo4j/graphql/issues/1249", () => {
let schema: GraphQLSchema;
let driver: Driver;
let neo4j: Neo4jHelper;

const typeDefs = `
type Bulk
let Bulk: UniqueType;
let Material: UniqueType;
let Supplier: UniqueType;
let typeDefs: string;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();
Bulk = new UniqueType("Bulk");
Material = new UniqueType("Material");
Supplier = new UniqueType("Supplier");
typeDefs = `
type ${Bulk}
@mutation(operations: [])
@node(labels: ["Bulk", "$tenant"]) {
id: ID!
supplierMaterialNumber: String!
material: Material! @relationship(type: "MATERIAL_BULK", direction: OUT)
material: ${Material}! @relationship(type: "MATERIAL_BULK", direction: OUT)
}

type Material @mutation(operations: []) {
type ${Material} @mutation(operations: []) {
id: ID!
itemNumber: String!

suppliers: [Supplier!]!
suppliers: [${Supplier}!]!
@relationship(type: "MATERIAL_SUPPLIER", properties: "RelationMaterialSupplier", direction: OUT)
}

type Supplier @mutation(operations: []) {
type ${Supplier} @mutation(operations: []) {
id: ID!
name: String
supplierId: String!
Expand All @@ -55,10 +67,6 @@ describe("https://github.com/neo4j/graphql/issues/1249", () => {
supplierMaterialNumber: String!
}
`;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();
});

afterAll(async () => {
Expand All @@ -74,7 +82,7 @@ describe("https://github.com/neo4j/graphql/issues/1249", () => {

const query = /* GraphQL */ `
query {
bulks {
${Bulk.plural} {
supplierMaterialNumber
material {
id
Expand All @@ -101,7 +109,7 @@ describe("https://github.com/neo4j/graphql/issues/1249", () => {

expect(res.errors).toBeUndefined();
expect(res.data).toEqual({
bulks: [],
[Bulk.plural]: [],
});
});
});
125 changes: 66 additions & 59 deletions packages/graphql/tests/integration/issues/1760.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,77 @@
* limitations under the License.
*/

import { gql } from "graphql-tag";
import type { GraphQLSchema } from "graphql";
import { graphql } from "graphql";
import type { Driver } from "neo4j-driver";
import { getQuerySource } from "../../utils/get-query-source";
import { Neo4jGraphQL } from "../../../src";
import Neo4jHelper from "../neo4j";
import { createBearerToken } from "../../utils/create-bearer-token";
import { UniqueType } from "../../utils/graphql-types";
import Neo4jHelper from "../neo4j";

describe("https://github.com/neo4j/graphql/issues/1760", () => {
let schema: GraphQLSchema;
let driver: Driver;
let neo4j: Neo4jHelper;
const secret = "secret";

let ApplicationVariant: UniqueType;
let NameDetails: UniqueType;
let Market: UniqueType;
let BaseObject: UniqueType;
let typeDefs: string;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();
const typeDefs = gql`
type JWTPayload @jwt {
roles: [String!]!
}

interface BusinessObject {
id: ID!
nameDetails: NameDetails
}

type ApplicationVariant implements BusinessObject
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
markets: [Market!]! @relationship(type: "HAS_MARKETS", direction: OUT)
id: ID! @unique
relatedId: ID
@cypher(statement: "MATCH (this)<-[:HAS_BASE]-(n:BaseObject) RETURN n.id as res", columnName: "res")
baseObject: BaseObject! @relationship(type: "HAS_BASE", direction: IN)
current: Boolean!
nameDetails: NameDetails @relationship(type: "HAS_NAME", direction: OUT)
}
ApplicationVariant = new UniqueType("ApplicationVariant");
NameDetails = new UniqueType("NameDetails");
Market = new UniqueType("Market");
BaseObject = new UniqueType("BaseObject");

type NameDetails
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: [])
@query(read: false, aggregate: false) {
fullName: String!
}

type Market implements BusinessObject
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
id: ID! @unique
nameDetails: NameDetails @relationship(type: "HAS_NAME", direction: OUT)
}
typeDefs = `
type JWTPayload @jwt {
roles: [String!]!
}

interface BusinessObject {
id: ID!
nameDetails: ${NameDetails}
}

type ${ApplicationVariant} implements BusinessObject
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
markets: [${Market}!]! @relationship(type: "HAS_MARKETS", direction: OUT)
id: ID! @unique
relatedId: ID
@cypher(statement: "MATCH (this)<-[:HAS_BASE]-(n:${BaseObject}) RETURN n.id as res", columnName: "res")
baseObject: ${BaseObject}! @relationship(type: "HAS_BASE", direction: IN)
current: Boolean!
nameDetails: ${NameDetails} @relationship(type: "HAS_NAME", direction: OUT)
}

type ${NameDetails}
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: [])
@query(read: false, aggregate: false) {
fullName: String!
}

type ${Market} implements BusinessObject
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
id: ID! @unique
nameDetails: ${NameDetails} @relationship(type: "HAS_NAME", direction: OUT)
}

type ${BaseObject}
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
id: ID! @id @unique
}
`;

type BaseObject
@authorization(validate: [{ when: [BEFORE], where: { jwt: { roles_INCLUDES: "ALL" } } }])
@mutation(operations: []) {
id: ID! @id @unique
}
`;
const neoGraphql = new Neo4jGraphQL({ typeDefs, driver, features: { authorization: { key: secret } } });
schema = await neoGraphql.getSchema();
});
Expand All @@ -86,9 +97,17 @@ describe("https://github.com/neo4j/graphql/issues/1760", () => {
});

test("provided query does not result in an error", async () => {
const query = gql`
query getApplicationVariants($where: ApplicationVariantWhere, $options: ApplicationVariantOptions) {
applicationVariants(where: $where, options: $options) {
const query = `
query getApplicationVariants {
${ApplicationVariant.plural}(where: {
current: true,
}, options: {
sort: {
relatedId: ASC,
},
offset: 0,
limit: 50,
},) {
relatedId
nameDetailsConnection {
edges {
Expand Down Expand Up @@ -124,19 +143,7 @@ describe("https://github.com/neo4j/graphql/issues/1760", () => {
const token = createBearerToken(secret, { roles: ["ALL"] });
const result = await graphql({
schema,
source: getQuerySource(query),
variableValues: {
where: {
current: true,
},
options: {
sort: {
relatedId: "ASC",
},
offset: 0,
limit: 50,
},
},
source: query,
contextValue: neo4j.getContextValues({ token }),
});

Expand Down
Loading
Loading