UNPKG

@neo4j/graphql

Version:

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations

67 lines 3.36 kB
"use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.withConnectionObjectType = withConnectionObjectType; const graphql_1 = require("graphql"); const PageInfo_1 = require("../../graphql/objects/PageInfo"); const InterfaceEntityAdapter_1 = require("../../schema-model/entity/model-adapters/InterfaceEntityAdapter"); const UnionEntityAdapter_1 = require("../../schema-model/entity/model-adapters/UnionEntityAdapter"); const RelationshipAdapter_1 = require("../../schema-model/relationship/model-adapters/RelationshipAdapter"); function withConnectionObjectType({ relationshipAdapter, composer, }) { const typeName = relationshipAdapter.operations.connectionFieldTypename; if (composer.has(typeName)) { return composer.getOTC(typeName); } const connectionObjectType = composer.getOrCreateOTC(typeName); if (relationshipAdapter.isReadable()) { connectionObjectType.addFields({ edges: withRelationshipObjectType({ relationshipAdapter, composer }).NonNull.List.NonNull, totalCount: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt), pageInfo: new graphql_1.GraphQLNonNull(PageInfo_1.PageInfo), }); } const isTargetUnion = relationshipAdapter.target instanceof UnionEntityAdapter_1.UnionEntityAdapter; const isSourceInterface = relationshipAdapter.source instanceof InterfaceEntityAdapter_1.InterfaceEntityAdapter; if (relationshipAdapter.aggregate && !isTargetUnion && !isSourceInterface) { const connectionObjectType = composer.getOrCreateOTC(typeName); connectionObjectType.addFields({ aggregate: composer.getOTC(relationshipAdapter.operations.getAggregateFieldTypename()).NonNull, }); } return connectionObjectType; } function withRelationshipObjectType({ relationshipAdapter, composer, }) { const typeName = relationshipAdapter.operations.relationshipFieldTypename; if (composer.has(typeName)) { return composer.getOTC(typeName); } const relationshipObjectType = composer.createObjectTC({ name: typeName, fields: { cursor: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString), node: `${relationshipAdapter.target.name}!` }, }); // TODO: RelationshipDeclarationAdapter is handled by doForRelationshipDeclaration - improve if (relationshipAdapter instanceof RelationshipAdapter_1.RelationshipAdapter && relationshipAdapter.hasAnyProperties) { relationshipObjectType.addFields({ properties: composer.getOTC(relationshipAdapter.propertiesTypeName).NonNull, }); } return relationshipObjectType; } //# sourceMappingURL=connection-object-type.js.map