polen
Version:
A framework for delightful GraphQL developer portals
98 lines • 3.51 kB
TypeScript
/**
* Semantic Node Types for GraphQL Interactive
*
* This module defines the semantic node types used to represent
* GraphQL schema information alongside tree-sitter syntax nodes.
*/
import type { GraphQLArgument, GraphQLEnumType, GraphQLField, GraphQLInputField, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType } from 'graphql';
/**
* Wrapper for output fields that need parent type context
*/
export interface OutputFieldNode {
kind: 'OutputField';
parentType: GraphQLObjectType | GraphQLInterfaceType;
fieldDef: GraphQLField<any, any>;
}
/**
* Wrapper for input fields that need parent type context
*/
export interface InputFieldNode {
kind: 'InputField';
parentType: GraphQLInputObjectType;
fieldDef: GraphQLInputField;
}
/**
* Wrapper for arguments that need parent field context
*/
export interface ArgumentNode {
kind: 'Argument';
parentType: GraphQLObjectType | GraphQLInterfaceType;
parentField: GraphQLField<any, any>;
argumentDef: GraphQLArgument;
}
/**
* Wrapper for operation definitions
*/
export interface OperationNode {
kind: 'Operation';
type: 'query' | 'mutation' | 'subscription';
name?: string;
}
/**
* Wrapper for variable references
*/
export interface VariableNode {
kind: 'Variable';
name: string;
type?: GraphQLInputType;
}
/**
* Wrapper for fragment definitions
*/
export interface FragmentNode {
kind: 'Fragment';
name: string;
onType: GraphQLNamedType;
}
/**
* Wrapper for invalid fields that don't exist in the schema
*/
export interface InvalidFieldNode {
kind: 'InvalidField';
fieldName: string;
parentType: GraphQLObjectType | GraphQLInterfaceType;
suggestion?: string;
}
/**
* Union of all semantic node types
*
* This union represents the different kinds of semantic information that can
* be attached to GraphQL tokens during parsing. It includes both GraphQL's
* native type classes (for type references) and our custom wrapper interfaces
* (for context-dependent elements like fields and arguments).
*
* @example
* ```typescript
* // Type reference - uses GraphQL native class
* const userType: SemanticNode = schema.getType('User')
*
* // Field reference - uses custom wrapper with context
* const fieldSemantic: SemanticNode = {
* kind: 'OutputField',
* parentType: userType,
* fieldDef: userType.getFields()['name']
* }
* ```
*/
export type SemanticNode = GraphQLObjectType | GraphQLScalarType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType | GraphQLInputObjectType | OutputFieldNode | InputFieldNode | ArgumentNode | OperationNode | VariableNode | FragmentNode | InvalidFieldNode;
/**
* Type guards for our custom wrapper types
*/
export declare function isOutputField(node: SemanticNode | undefined): node is OutputFieldNode;
export declare function isInputField(node: SemanticNode | undefined): node is InputFieldNode;
export declare function isArgument(node: SemanticNode | undefined): node is ArgumentNode;
export declare function isOperation(node: SemanticNode | undefined): node is OperationNode;
export declare function isVariable(node: SemanticNode | undefined): node is VariableNode;
export declare function isFragment(node: SemanticNode | undefined): node is FragmentNode;
export declare function isInvalidField(node: SemanticNode | undefined): node is InvalidFieldNode;
//# sourceMappingURL=semantic-nodes.d.ts.map