UNPKG

@graphql-hive/laboratory

Version:

[Hive](https://the-guild.dev/graphql/hive) is a fully open-source schema registry, analytics, metrics and gateway for [GraphQL federation](https://the-guild.dev/graphql/hive/federation) and other GraphQL APIs.

39 lines (38 loc) 1.87 kB
import { OperationTypeNode, GraphQLField, GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLSchema, GraphQLUnionType } from 'graphql'; export type SchemaPathSegment = { kind: 'field'; name: string; } | { kind: 'typeCondition'; typeName: string; }; /** A type a path can be positioned on and still have somewhere to go. */ export type SchemaPathParentType = GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType; export type SchemaPathStep = { segment: SchemaPathSegment; /** The type the segment was resolved against. */ parentType: SchemaPathParentType; /** null on a type-condition step, which narrows rather than selects. */ field: GraphQLField<unknown, unknown> | null; /** The named type the path sits on after this step. */ type: GraphQLNamedType; }; export declare function encodeTypeConditionSegment(typeName: string): string; /** Returns the type name, or null when the segment is an ordinary field. */ export declare function decodeTypeConditionSegment(segment: string): string | null; export declare function isTypeConditionSegment(segment: string): boolean; export declare function parseSchemaPath(path: string): { operation: OperationTypeNode | null; segments: SchemaPathSegment[]; }; /** * Field names only. Search matches against this so a type condition cannot match * on the spelling of its own sigil, and labels read as GraphQL rather than as paths. */ export declare function toFieldSegments(segments: readonly SchemaPathSegment[]): string[]; /** * Walks a dotted path against the schema, one step per segment. Returns null on * any miss rather than a partial walk, so a caller can never mistake the last * type it happened to resolve for the one the path named. */ export declare function resolveSchemaPath(path: string, schema: GraphQLSchema): SchemaPathStep[] | null;