Interfaces.d.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { GraphQLSchema, GraphQLField, ExecutionResult, GraphQLType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLIsTypeOfFn, GraphQLTypeResolver, GraphQLScalarType, GraphQLNamedType, DocumentNode, ASTNode } from 'graphql';
  2. import { SchemaDirectiveVisitor } from './schemaVisitor';
  3. export declare type UnitOrList<Type> = Type | Array<Type>;
  4. export interface IResolverValidationOptions {
  5. requireResolversForArgs?: boolean;
  6. requireResolversForNonScalar?: boolean;
  7. requireResolversForAllFields?: boolean;
  8. requireResolversForResolveType?: boolean;
  9. allowResolversNotInSchema?: boolean;
  10. }
  11. export interface IAddResolveFunctionsToSchemaOptions {
  12. schema: GraphQLSchema;
  13. resolvers: IResolvers;
  14. resolverValidationOptions?: IResolverValidationOptions;
  15. inheritResolversFromInterfaces?: boolean;
  16. }
  17. export interface IResolverOptions<TSource = any, TContext = any, TArgs = any> {
  18. fragment?: string;
  19. resolve?: IFieldResolver<TSource, TContext, TArgs>;
  20. subscribe?: IFieldResolver<TSource, TContext, TArgs>;
  21. __resolveType?: GraphQLTypeResolver<TSource, TContext>;
  22. __isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext>;
  23. }
  24. export declare type Transform = {
  25. transformSchema?: (schema: GraphQLSchema) => GraphQLSchema;
  26. transformRequest?: (originalRequest: Request) => Request;
  27. transformResult?: (result: Result) => Result;
  28. };
  29. export interface IGraphQLToolsResolveInfo extends GraphQLResolveInfo {
  30. mergeInfo?: MergeInfo;
  31. }
  32. export interface IDelegateToSchemaOptions<TContext = {
  33. [key: string]: any;
  34. }> {
  35. schema: GraphQLSchema;
  36. operation: Operation;
  37. fieldName: string;
  38. args?: {
  39. [key: string]: any;
  40. };
  41. context: TContext;
  42. info: IGraphQLToolsResolveInfo;
  43. transforms?: Array<Transform>;
  44. skipValidation?: boolean;
  45. }
  46. export declare type MergeInfo = {
  47. delegate: (type: 'query' | 'mutation' | 'subscription', fieldName: string, args: {
  48. [key: string]: any;
  49. }, context: {
  50. [key: string]: any;
  51. }, info: GraphQLResolveInfo, transforms?: Array<Transform>) => any;
  52. delegateToSchema<TContext>(options: IDelegateToSchemaOptions<TContext>): any;
  53. fragments: Array<{
  54. field: string;
  55. fragment: string;
  56. }>;
  57. };
  58. export declare type IFieldResolver<TSource, TContext, TArgs = Record<string, any>> = (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo & {
  59. mergeInfo: MergeInfo;
  60. }) => any;
  61. export declare type ITypedef = (() => ITypedef[]) | string | DocumentNode | ASTNode;
  62. export declare type ITypeDefinitions = ITypedef | ITypedef[];
  63. export declare type IResolverObject<TSource = any, TContext = any, TArgs = any> = {
  64. [key: string]: IFieldResolver<TSource, TContext, TArgs> | IResolverOptions<TSource, TContext> | IResolverObject<TSource, TContext>;
  65. };
  66. export declare type IEnumResolver = {
  67. [key: string]: string | number;
  68. };
  69. export interface IResolvers<TSource = any, TContext = any> {
  70. [key: string]: (() => any) | IResolverObject<TSource, TContext> | IResolverOptions<TSource, TContext> | GraphQLScalarType | IEnumResolver;
  71. }
  72. export declare type IResolversParameter = Array<IResolvers | ((mergeInfo: MergeInfo) => IResolvers)> | IResolvers | ((mergeInfo: MergeInfo) => IResolvers);
  73. export interface ILogger {
  74. log: (message: string | Error) => void;
  75. }
  76. export interface IConnectorCls<TContext = any> {
  77. new (context?: TContext): any;
  78. }
  79. export declare type IConnectorFn<TContext = any> = (context?: TContext) => any;
  80. export declare type IConnector<TContext = any> = IConnectorCls<TContext> | IConnectorFn<TContext>;
  81. export declare type IConnectors<TContext = any> = {
  82. [key: string]: IConnector<TContext>;
  83. };
  84. export interface IExecutableSchemaDefinition<TContext = any> {
  85. typeDefs: ITypeDefinitions;
  86. resolvers?: IResolvers<any, TContext> | Array<IResolvers<any, TContext>>;
  87. connectors?: IConnectors<TContext>;
  88. logger?: ILogger;
  89. allowUndefinedInResolve?: boolean;
  90. resolverValidationOptions?: IResolverValidationOptions;
  91. directiveResolvers?: IDirectiveResolvers<any, TContext>;
  92. schemaDirectives?: {
  93. [name: string]: typeof SchemaDirectiveVisitor;
  94. };
  95. parseOptions?: GraphQLParseOptions;
  96. inheritResolversFromInterfaces?: boolean;
  97. }
  98. export declare type IFieldIteratorFn = (fieldDef: GraphQLField<any, any>, typeName: string, fieldName: string) => void;
  99. export declare type NextResolverFn = () => Promise<any>;
  100. export declare type DirectiveResolverFn<TSource = any, TContext = any> = (next: NextResolverFn, source: TSource, args: {
  101. [argName: string]: any;
  102. }, context: TContext, info: GraphQLResolveInfo) => any;
  103. export interface IDirectiveResolvers<TSource = any, TContext = any> {
  104. [directiveName: string]: DirectiveResolverFn<TSource, TContext>;
  105. }
  106. export declare type IMockFn = GraphQLFieldResolver<any, any>;
  107. export declare type IMocks = {
  108. [key: string]: IMockFn;
  109. };
  110. export declare type IMockTypeFn = (type: GraphQLType, typeName?: string, fieldName?: string) => GraphQLFieldResolver<any, any>;
  111. export interface IMockOptions {
  112. schema: GraphQLSchema;
  113. mocks?: IMocks;
  114. preserveResolvers?: boolean;
  115. }
  116. export interface IMockServer {
  117. query: (query: string, vars?: {
  118. [key: string]: any;
  119. }) => Promise<ExecutionResult>;
  120. }
  121. export declare type MergeTypeCandidate = {
  122. schema?: GraphQLSchema;
  123. type: GraphQLNamedType;
  124. };
  125. export declare type TypeWithResolvers = {
  126. type: GraphQLNamedType;
  127. resolvers?: IResolvers;
  128. };
  129. export declare type VisitTypeResult = GraphQLNamedType | TypeWithResolvers | null;
  130. export declare type VisitType = (name: string, candidates: Array<MergeTypeCandidate>) => VisitTypeResult;
  131. export declare type Operation = 'query' | 'mutation' | 'subscription';
  132. export declare type Request = {
  133. document: DocumentNode;
  134. variables: Record<string, any>;
  135. extensions?: Record<string, any>;
  136. };
  137. export declare type Result = ExecutionResult & {
  138. extensions?: Record<string, any>;
  139. };
  140. export declare type ResolveType<T extends GraphQLType> = (type: T) => T;
  141. export declare type GraphQLParseOptions = {
  142. noLocation?: boolean;
  143. allowLegacySDLEmptyFields?: boolean;
  144. allowLegacySDLImplementsInterfaces?: boolean;
  145. experimentalFragmentVariables?: boolean;
  146. };