UNPKG

@neo4j/graphql

Version:

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

404 lines 12.9 kB
import type Cypher from "@neo4j/cypher-builder"; import type { EventEmitter } from "events"; import type { DirectiveNode, InputValueDefinitionNode, TypeNode } from "graphql"; import type { Directive } from "graphql-compose"; import type { ResolveTree } from "graphql-parse-resolve-info"; import type { JWTVerifyOptions, RemoteJWKSetOptions } from "jose"; import type { Integer } from "neo4j-driver"; import type { Neo4jGraphQLSubscriptionsCDCEngine } from "../classes/subscription/Neo4jGraphQLSubscriptionsCDCEngine"; import type { RelationshipNestedOperationsOption, RelationshipQueryDirectionOption } from "../constants"; import type { Neo4jGraphQLSchemaModel } from "../schema-model/Neo4jGraphQLSchemaModel"; import type { DefaultAnnotationValue } from "../schema-model/annotation/DefaultAnnotation"; import type { FulltextField } from "../schema-model/annotation/FulltextAnnotation"; import type { VectorField } from "../schema-model/annotation/VectorAnnotation"; import type { RelationshipDirection } from "../schema-model/relationship/Relationship"; import type { JwtPayload } from "./jwt-payload"; import type { Neo4jGraphQLContext } from "./neo4j-graphql-context"; export { Node } from "../classes"; export type AuthorizationContext = { jwt?: JwtPayload; jwtParam: Cypher.Param; isAuthenticated: boolean; isAuthenticatedParam: Cypher.Param; claims?: Map<string, string>; }; export type FulltextContext = { index: FulltextField; queryName: string; queryType: string; scoreVariable: Cypher.Variable; }; export type VectorContext = { index: VectorField; queryName: string; queryType: string; scoreVariable: Cypher.Variable; vectorSettings: Neo4jVectorSettings; }; export type FullText = { indexes: FulltextContext[]; }; /** * Metadata about a field.type on either * FieldDefinitionNode or InputValueDefinitionNode. */ export interface TypeMeta { name: string; array?: boolean; required: boolean; pretty: string; input: { where: { type: string; pretty: string; }; create: { type: string; pretty: string; }; update: { type: string; pretty: string; }; }; originalType?: TypeNode; } export type Unique = { constraintName: string; }; export interface Callback { operations: CallbackOperations[]; callbackName: string; } export type SelectableOptions = { onRead: boolean; onAggregate: boolean; }; export type SettableOptions = { onCreate: boolean; onUpdate: boolean; }; export type FilterableOptions = { byValue: boolean; byAggregate: boolean; }; /** * Representation a ObjectTypeDefinitionNode field. */ export interface BaseField { fieldName: string; typeMeta: TypeMeta; otherDirectives: DirectiveNode[]; arguments: InputValueDefinitionNode[]; private?: boolean; description?: string; dbPropertyName?: string; dbPropertyNameUnescaped?: string; unique?: Unique; selectableOptions: SelectableOptions; settableOptions: SettableOptions; filterableOptions: FilterableOptions; } /** * Representation of the `@relationship` directive and its meta. */ export interface RelationField extends BaseField { direction: RelationshipDirection; typeUnescaped: string; type: string; connectionPrefix?: string; inherited: boolean; properties?: string; union?: UnionField; interface?: InterfaceField; queryDirection: RelationshipQueryDirectionOption; nestedOperations: RelationshipNestedOperationsOption[]; aggregate: boolean; } export interface ConnectionField extends BaseField { relationship: RelationField; relationshipTypeName: string; } /** * Representation of the `@cypher` directive and its meta. */ export interface CypherField extends BaseField { statement: string; columnName: string; isEnum: boolean; isScalar: boolean; } /** * Representation of any field thats not * a cypher directive or relationship directive * String, Int, Float, ID, Boolean... (custom scalars). */ export interface PrimitiveField extends BaseField { autogenerate?: boolean; defaultValue?: any; coalesceValue?: any; callback?: Callback; isGlobalIdField?: boolean; } export type CustomScalarField = BaseField; export interface CustomEnumField extends BaseField { kind: string; defaultValue?: string | string[]; coalesceValue?: string | string[]; } export interface UnionField extends BaseField { nodes?: string[]; } export interface CustomResolverField extends BaseField { requiredFields: Record<string, ResolveTree>; } export interface InterfaceField extends BaseField { implementations?: string[]; } export type ObjectField = BaseField; export interface TemporalField extends PrimitiveField { timestamps?: TimeStampOperations[]; } export type PointField = BaseField; export type SortDirection = "ASC" | "DESC"; export interface GraphQLSortArg { [field: string]: SortDirection; } export interface NestedGraphQLSortArg { [field: string]: GraphQLSortArg; } export interface ConnectionSortArg { node?: GraphQLSortArg; edge?: GraphQLSortArg; } export interface ConnectionQueryArgs { where?: ConnectionWhereArg; first?: number; after?: string; sort?: ConnectionSortArg[]; } /** * Representation of the options arg * passed to resolvers. */ export interface GraphQLSortingAndPaginationArgs { limit?: number | Integer; offset?: number | Integer; sort?: GraphQLSortArg[]; } /** * Representation of the where arg * passed to resolvers. */ export interface GraphQLWhereArg { [k: string]: any; AND?: GraphQLWhereArg[]; OR?: GraphQLWhereArg[]; NOT?: GraphQLWhereArg; } export interface ConnectionWhereArg { node?: GraphQLWhereArg; edge?: GraphQLWhereArg; AND?: ConnectionWhereArg[]; OR?: ConnectionWhereArg[]; NOT?: ConnectionWhereArg; } export type TimeStampOperations = "CREATE" | "UPDATE"; export type CallbackOperations = "CREATE" | "UPDATE"; export interface CypherQueryOptions { /** * Configure the runtime used: {@link https://neo4j.com/docs/cypher-manual/current/planning-and-tuning/runtimes/concepts | Cypher Runtimes} * "interpreted" runtime option is deprecated. */ runtime?: "interpreted" | "slotted" | "pipelined" | "parallel"; planner?: "cost" | "idp" | "dp"; updateStrategy?: "default" | "eager"; expressionEngine?: "default" | "interpreted" | "compiled"; operatorEngine?: "default" | "interpreted" | "compiled"; interpretedPipesFallback?: "default" | "disabled" | "whitelisted_plans_only" | "all"; replan?: "default" | "force" | "skip"; addVersionPrefix?: boolean; } /** Input field for graphql-compose */ export type InputField = { type: string; defaultValue?: DefaultAnnotationValue; directives?: Directive[]; } | string; /** Raw event metadata returned from queries */ export type NodeSubscriptionMeta = { event: "create" | "update" | "delete"; typename: string; properties: { old: Record<string, any>; new: Record<string, any>; }; id: Integer | string | number; timestamp: Integer | string | number; }; export type RelationshipSubscriptionMeta = RelationshipSubscriptionMetaTypenameParameters | RelationshipSubscriptionMetaLabelsParameters; type RelationshipSubscriptionMetaCommonParameters = { event: "create_relationship" | "delete_relationship"; relationshipName: string; id_from: Integer | string | number; id_to: Integer | string | number; properties: { from: Record<string, any>; to: Record<string, any>; relationship: Record<string, any>; }; id: Integer | string | number; timestamp: Integer | string | number; }; export type RelationshipSubscriptionMetaTypenameParameters = RelationshipSubscriptionMetaCommonParameters & { fromTypename: string; toTypename: string; }; export type RelationshipSubscriptionMetaLabelsParameters = RelationshipSubscriptionMetaCommonParameters & { fromLabels: string[]; toLabels: string[]; }; export type EventMeta = NodeSubscriptionMeta | RelationshipSubscriptionMeta; export type NodeSubscriptionsEvent = { event: "create"; typename: string; properties: { old: undefined; new: Record<string, any>; }; id: string; timestamp: number; } | { event: "update"; typename: string; properties: { old: Record<string, any>; new: Record<string, any>; }; id: string; timestamp: number; } | { event: "delete"; typename: string; properties: { old: Record<string, any>; new: undefined; }; id: string; timestamp: number; }; /** Serialized subscription event */ export type SubscriptionsEvent = NodeSubscriptionsEvent; export type SubscriptionEngineContext = { schemaModel: Neo4jGraphQLSchemaModel; }; /** Defines a custom mechanism to transport subscription events internally between servers */ export interface Neo4jGraphQLSubscriptionsEngine { events: EventEmitter; /** To be called, if needed, in getSchema */ init?(context: SubscriptionEngineContext): Promise<void>; /** Stops subscription */ close(): void; } export type CallbackReturnValue = string | number | boolean | undefined | null | Array<CallbackReturnValue>; export type Neo4jGraphQLCallback = (parent: Record<string, unknown> | undefined, args: Record<string, never>, context: Neo4jGraphQLContext) => CallbackReturnValue | Promise<CallbackReturnValue>; export type Neo4jGraphQLCallbacks = Record<string, Neo4jGraphQLCallback>; export interface Neo4jStringFiltersSettings { GT?: boolean; GTE?: boolean; LT?: boolean; LTE?: boolean; MATCHES?: boolean; CASE_INSENSITIVE?: boolean; } export interface Neo4jIDFiltersSettings { MATCHES?: boolean; } export interface Neo4jFiltersSettings { String?: Neo4jStringFiltersSettings; ID?: Neo4jIDFiltersSettings; } export interface Neo4jPopulatedBySettings { callbacks?: Neo4jGraphQLCallbacks; } export interface Neo4jAuthorizationSettings { key: Key | ((context: Neo4jGraphQLContext) => Key); verify?: boolean; verifyOptions?: JWTVerifyOptions; } export interface Neo4jVectorSettings { ["VertexAI"]?: { token: string; projectId: string; model?: string; region?: string; }; ["OpenAI"]?: { token: string; model?: string; dimensions?: number; }; ["AzureOpenAI"]?: { token: string; resource: string; deployment: string; }; ["Bedrock"]?: { accessKeyId: string; secretAccessKey: string; model?: string; region?: string; }; } export interface RemoteJWKS { url: string | URL; options?: RemoteJWKSetOptions; } export type Key = string | RemoteJWKS; /** Options to enable extra capabilities on @neo4j/graphql API */ export type Neo4jFeaturesSettings = { filters?: Neo4jFiltersSettings; populatedBy?: Neo4jPopulatedBySettings; authorization?: Neo4jAuthorizationSettings; subscriptions?: boolean | Neo4jGraphQLSubscriptionsCDCEngine; /** If set to `true`, removes `@neo4j/graphql` fields that are marked as deprecated to reduce schema size. * * NOTE: this will not remove user defined deprecated fields **/ excludeDeprecatedFields?: { mutationOperations?: boolean; aggregationFilters?: boolean; aggregationFiltersOutsideConnection?: boolean; relationshipFilters?: boolean; attributeFilters?: boolean; }; /** Options for disabling automatic escaping of potentially unsafe strings. * * **WARNING**: Changing these options may lead to code injection and unsafe Cypher. */ unsafeEscapeOptions?: { /** Disables automatic escaping of node labels. * * **WARNING**: Disabling label escaping may lead to code injection and unsafe Cypher. */ disableNodeLabelEscaping?: boolean; /** Disables automatic escaping of relationship types. * * **WARNING**: Disabling type escaping may lead to code injection and unsafe Cypher. */ disableRelationshipTypeEscaping?: boolean; }; vector?: Neo4jVectorSettings; limitRequired?: boolean; complexityEstimators?: boolean; }; /** Parsed features used in context */ export type ContextFeatures = Neo4jFeaturesSettings & { subscriptionsEngine?: Neo4jGraphQLSubscriptionsEngine; }; export type PredicateReturn = { predicate: Cypher.Predicate | undefined; preComputedSubqueries?: Cypher.CompositeClause | undefined; }; export type CypherFieldReferenceMap = Record<string, Cypher.Node | Cypher.Variable>; //# sourceMappingURL=index.d.ts.map