Skip to content

Commit

Permalink
Add tests on top level interface connection
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala committed Mar 5, 2024
1 parent 1b57ee6 commit 7ea3d92
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import type { EntitySelection } from "../../ast/selection/EntitySelection";
import { NodeSelection } from "../../ast/selection/NodeSelection";
import { RelationshipSelection } from "../../ast/selection/RelationshipSelection";
import { getConcreteEntities } from "../../utils/get-concrete-entities";
import { isConcreteEntity } from "../../utils/is-concrete-entity";
import { isInterfaceEntity } from "../../utils/is-interface-entity";
import { isRelationshipEntity } from "../../utils/is-relationship-entity";
import { isUnionEntity } from "../../utils/is-union-entity";
import type { QueryASTFactory } from "../QueryASTFactory";
import { findFieldsByNameInFieldsByTypeNameField } from "../parsers/find-fields-by-name-in-fields-by-type-name-field";
Expand Down Expand Up @@ -113,14 +113,14 @@ export class ConnectionFactory {
// These sort fields will be duplicated on nested "CompositeConnectionPartial"

// TODO: this if shouldn't be needed
if (relationship) {
this.hydrateConnectionOperationsASTWithSort({
entityOrRel: relationship,
resolveTree,
operation: compositeConnectionOp,
context,
});
}
// if (relationship) {
this.hydrateConnectionOperationsASTWithSort({
entityOrRel: relationship ?? target,
resolveTree,
operation: compositeConnectionOp,
context,
});
// }
return compositeConnectionOp;
}

Expand Down Expand Up @@ -183,13 +183,13 @@ export class ConnectionFactory {
operation,
context,
}: {
entityOrRel: ConcreteEntityAdapter | RelationshipAdapter;
entityOrRel: EntityAdapter | RelationshipAdapter;
resolveTree: ResolveTree;
operation: T;
context: Neo4jGraphQLTranslationContext;
}): T {
let options: Pick<ConnectionQueryArgs, "first" | "after" | "sort"> | undefined;
const target = isConcreteEntity(entityOrRel) ? entityOrRel : entityOrRel.target;
const target = isRelationshipEntity(entityOrRel) ? entityOrRel.target : entityOrRel;
if (!isUnionEntity(target)) {
options = this.queryASTFactory.operationsFactory.getConnectionOptions(target, resolveTree.args);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import type Cypher from "@neo4j/cypher-builder";
import { SCORE_FIELD } from "../../../graphql/directives/fulltext";
import type { EntityAdapter } from "../../../schema-model/entity/EntityAdapter";
import type { ConcreteEntityAdapter } from "../../../schema-model/entity/model-adapters/ConcreteEntityAdapter";
import { RelationshipAdapter } from "../../../schema-model/relationship/model-adapters/RelationshipAdapter";
import type { ConnectionSortArg, GraphQLOptionsArg, GraphQLSortArg, NestedGraphQLSortArg } from "../../../types";
import type { Neo4jGraphQLTranslationContext } from "../../../types/neo4j-graphql-translation-context";
Expand All @@ -31,6 +30,7 @@ import { FulltextScoreSort } from "../ast/sort/FulltextScoreSort";
import { PropertySort } from "../ast/sort/PropertySort";
import type { Sort } from "../ast/sort/Sort";
import { isConcreteEntity } from "../utils/is-concrete-entity";
import { isRelationshipEntity } from "../utils/is-relationship-entity";
import { isUnionEntity } from "../utils/is-union-entity";
import type { QueryASTFactory } from "./QueryASTFactory";

Expand All @@ -52,7 +52,7 @@ export class SortAndPaginationFactory {

public createConnectionSortFields(
options: ConnectionSortArg,
entityOrRel: ConcreteEntityAdapter | RelationshipAdapter,
entityOrRel: EntityAdapter | RelationshipAdapter,
context: Neo4jGraphQLTranslationContext
): { edge: Sort[]; node: Sort[] } {
if (isConcreteEntity(entityOrRel)) {
Expand All @@ -66,14 +66,32 @@ export class SortAndPaginationFactory {
node: nodeSortFields,
};
}
if (isRelationshipEntity(entityOrRel)) {
const nodeSortFields = this.createPropertySort({
optionArg: options.node ?? {},
entity: entityOrRel.target,
context,
});
const edgeSortFields = this.createPropertySort({
optionArg: options.edge || {},
entity: entityOrRel,
context,
});
return {
edge: edgeSortFields,
node: nodeSortFields,
};
}
// Is union or interface

const nodeSortFields = this.createPropertySort({
optionArg: options.node ?? {},
entity: entityOrRel.target,
entity: entityOrRel,
context,
});
const edgeSortFields = this.createPropertySort({ optionArg: options.edge || {}, entity: entityOrRel, context });

return {
edge: edgeSortFields,
edge: [],
node: nodeSortFields,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { EntityAdapter } from "../../../schema-model/entity/EntityAdapter";
import { RelationshipAdapter } from "../../../schema-model/relationship/model-adapters/RelationshipAdapter";

export function isRelationshipEntity(entity: EntityAdapter | RelationshipAdapter): entity is RelationshipAdapter {
return entity instanceof RelationshipAdapter;
}
Loading

0 comments on commit 7ea3d92

Please sign in to comment.