connection.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { GraphQLNonNull, GraphQLObjectType } from 'graphql';
  2. import type {
  3. GraphQLNamedOutputType,
  4. GraphQLFieldConfigArgumentMap,
  5. GraphQLFieldConfig,
  6. GraphQLFieldResolver,
  7. ThunkObjMap,
  8. } from 'graphql';
  9. /**
  10. * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
  11. * whose return type is a connection type with forward pagination.
  12. */
  13. export declare const forwardConnectionArgs: GraphQLFieldConfigArgumentMap;
  14. /**
  15. * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
  16. * whose return type is a connection type with backward pagination.
  17. */
  18. export declare const backwardConnectionArgs: GraphQLFieldConfigArgumentMap;
  19. /**
  20. * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
  21. * whose return type is a connection type with bidirectional pagination.
  22. */
  23. export declare const connectionArgs: GraphQLFieldConfigArgumentMap;
  24. /**
  25. * A type alias for cursors in this implementation.
  26. */
  27. export declare type ConnectionCursor = string;
  28. /**
  29. * A type describing the arguments a connection field receives in GraphQL.
  30. */
  31. export interface ConnectionArguments {
  32. before?: ConnectionCursor | null;
  33. after?: ConnectionCursor | null;
  34. first?: number | null;
  35. last?: number | null;
  36. }
  37. export interface ConnectionConfig {
  38. name?: string;
  39. nodeType: GraphQLNamedOutputType | GraphQLNonNull<GraphQLNamedOutputType>;
  40. resolveNode?: GraphQLFieldResolver<any, any>;
  41. resolveCursor?: GraphQLFieldResolver<any, any>;
  42. edgeFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>;
  43. connectionFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>;
  44. }
  45. export interface GraphQLConnectionDefinitions {
  46. edgeType: GraphQLObjectType;
  47. connectionType: GraphQLObjectType;
  48. }
  49. /**
  50. * Returns a GraphQLObjectType for a connection with the given name,
  51. * and whose nodes are of the specified type.
  52. */
  53. export declare function connectionDefinitions(
  54. config: ConnectionConfig,
  55. ): GraphQLConnectionDefinitions;
  56. /**
  57. * A type designed to be exposed as a `Connection` over GraphQL.
  58. */
  59. export interface Connection<T> {
  60. edges: Array<Edge<T>>;
  61. pageInfo: PageInfo;
  62. }
  63. /**
  64. * A type designed to be exposed as a `Edge` over GraphQL.
  65. */
  66. export interface Edge<T> {
  67. node: T;
  68. cursor: ConnectionCursor;
  69. }
  70. /**
  71. * A type designed to be exposed as `PageInfo` over GraphQL.
  72. */
  73. export interface PageInfo {
  74. startCursor: ConnectionCursor | null;
  75. endCursor: ConnectionCursor | null;
  76. hasPreviousPage: boolean;
  77. hasNextPage: boolean;
  78. }