UNPKG

@graphql-eslint/eslint-plugin

Version:
108 lines (104 loc) 4.37 kB
import { GraphQLParseOptions } from '@graphql-tools/utils'; import { Linter, Rule, AST } from 'eslint'; import * as ESTree from 'estree'; import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode, GraphQLSchema, ASTKindToNode } from 'graphql'; import { GraphQLProjectConfig, IExtensions, IGraphQLProject } from 'graphql-config'; import { JSONSchema } from 'json-schema-to-ts'; import { GraphQLESTreeNode } from './estree-converter/types.js'; type FragmentSource = { filePath: string; document: FragmentDefinitionNode; }; type OperationSource = { filePath: string; document: OperationDefinitionNode; }; type SiblingOperations = { available: boolean; getFragment(fragmentName: string): FragmentSource[]; getFragments(): FragmentSource[]; getFragmentByType(typeName: string): FragmentSource[]; getFragmentsInUse(baseOperation: FragmentDefinitionNode | OperationDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[]; getOperation(operationName: string): OperationSource[]; getOperations(): OperationSource[]; getOperationByType(operationType: OperationTypeNode): OperationSource[]; }; declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations; type Schema = GraphQLSchema | null; type Pointer = string | string[]; interface ParserOptions { schema?: Pointer | Record<string, { headers: Record<string, string>; }>; documents?: Pointer; extensions?: IExtensions; include?: Pointer; exclude?: Pointer; projects?: Record<string, IGraphQLProject>; schemaOptions?: Omit<GraphQLParseOptions, 'assumeValidSDL'> & { headers: Record<string, string>; }; graphQLParserOptions?: Omit<GraphQLParseOptions, 'noLocation'>; skipGraphQLConfig?: boolean; filePath: string; /** @deprecated Use `documents` instead */ operations?: Pointer; } type ParserServices = { schema: Schema; siblingOperations: SiblingOperations; }; type GraphQLESLintParseResult = Linter.ESLintParseResult & { services: ParserServices; }; type Location = AST.SourceLocation | ESTree.Position; type ReportDescriptorLocation = { loc: Location; } | { node: { loc: Location; }; }; type ReportDescriptor = ReportDescriptorLocation & Rule.ReportDescriptorMessage & Rule.ReportDescriptorOptions; type GraphQLESLintRuleContext<Options = any[]> = Omit<Rule.RuleContext, 'options' | 'parserServices' | 'report'> & { options: Options; parserServices: ParserServices; report(descriptor: ReportDescriptor): void; }; type CategoryType = 'Operations' | 'Schema'; type RuleMetaDataDocs = Required<Rule.RuleMetaData>['docs']; type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & { category: CategoryType | CategoryType[]; requiresSchema?: true; requiresSiblings?: true; examples?: { title: string; code: string; usage?: T; }[]; configOptions?: T | { schema?: T; operations?: T; }; graphQLJSRuleName?: string; isDisabledForAllConfig?: true; }; type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & { [K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void; }; type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = { meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & { docs?: RuleDocsInfo<Options>; schema: Readonly<JSONSchema> | []; }; create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>; }; type ValueOf<T> = T[keyof T]; type Id<T> = { [P in keyof T]: T[P]; } & {}; type OmitDistributive<T, K extends PropertyKey> = T extends object ? Id<OmitRecursively<T, K>> : T; type OmitRecursively<T extends object, K extends PropertyKey> = Omit<{ [P in keyof T]: OmitDistributive<T[P], K>; }, K>; export { CategoryType as C, FragmentSource as F, GraphQLESLintParseResult as G, OmitRecursively as O, ParserOptions as P, ReportDescriptor as R, Schema as S, ValueOf as V, Pointer as a, ParserServices as b, GraphQLESLintRuleContext as c, RuleDocsInfo as d, GraphQLESLintRuleListener as e, GraphQLESLintRule as f, SiblingOperations as g, OperationSource as h, getSiblings as i };