123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true,
- });
- exports.connectionDefinitions = connectionDefinitions;
- exports.connectionArgs =
- exports.backwardConnectionArgs =
- exports.forwardConnectionArgs =
- void 0;
- var _graphql = require('graphql');
- /**
- * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
- * whose return type is a connection type with forward pagination.
- */
- const forwardConnectionArgs = Object.freeze({
- after: {
- type: _graphql.GraphQLString,
- description:
- 'Returns the items in the list that come after the specified cursor.',
- },
- first: {
- type: _graphql.GraphQLInt,
- description: 'Returns the first n items from the list.',
- },
- });
- /**
- * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
- * whose return type is a connection type with backward pagination.
- */
- exports.forwardConnectionArgs = forwardConnectionArgs;
- const backwardConnectionArgs = Object.freeze({
- before: {
- type: _graphql.GraphQLString,
- description:
- 'Returns the items in the list that come before the specified cursor.',
- },
- last: {
- type: _graphql.GraphQLInt,
- description: 'Returns the last n items from the list.',
- },
- });
- /**
- * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
- * whose return type is a connection type with bidirectional pagination.
- */
- exports.backwardConnectionArgs = backwardConnectionArgs;
- const connectionArgs = {
- ...forwardConnectionArgs,
- ...backwardConnectionArgs,
- };
- /**
- * A type alias for cursors in this implementation.
- */
- /**
- * A type describing the arguments a connection field receives in GraphQL.
- */
- exports.connectionArgs = connectionArgs;
- /**
- * Returns a GraphQLObjectType for a connection with the given name,
- * and whose nodes are of the specified type.
- */
- function connectionDefinitions(config) {
- var _config$name;
- const { nodeType } = config;
- const name =
- (_config$name = config.name) !== null && _config$name !== void 0
- ? _config$name
- : (0, _graphql.getNamedType)(nodeType).name;
- const edgeType = new _graphql.GraphQLObjectType({
- name: name + 'Edge',
- description: 'An edge in a connection.',
- fields: () => {
- var _config$edgeFields;
- return {
- node: {
- type: nodeType,
- resolve: config.resolveNode,
- description: 'The item at the end of the edge',
- },
- cursor: {
- type: new _graphql.GraphQLNonNull(_graphql.GraphQLString),
- resolve: config.resolveCursor,
- description: 'A cursor for use in pagination',
- },
- ...(0, _graphql.resolveObjMapThunk)(
- (_config$edgeFields = config.edgeFields) !== null &&
- _config$edgeFields !== void 0
- ? _config$edgeFields
- : {},
- ),
- };
- },
- });
- const connectionType = new _graphql.GraphQLObjectType({
- name: name + 'Connection',
- description: 'A connection to a list of items.',
- fields: () => {
- var _config$connectionFie;
- return {
- pageInfo: {
- type: new _graphql.GraphQLNonNull(pageInfoType),
- description: 'Information to aid in pagination.',
- },
- edges: {
- type: new _graphql.GraphQLList(edgeType),
- description: 'A list of edges.',
- },
- ...(0, _graphql.resolveObjMapThunk)(
- (_config$connectionFie = config.connectionFields) !== null &&
- _config$connectionFie !== void 0
- ? _config$connectionFie
- : {},
- ),
- };
- },
- });
- return {
- edgeType,
- connectionType,
- };
- }
- /**
- * A type designed to be exposed as a `Connection` over GraphQL.
- */
- /**
- * A type designed to be exposed as a `Edge` over GraphQL.
- */
- /**
- * The common page info type used by all connections.
- */
- const pageInfoType = new _graphql.GraphQLObjectType({
- name: 'PageInfo',
- description: 'Information about pagination in a connection.',
- fields: () => ({
- hasNextPage: {
- type: new _graphql.GraphQLNonNull(_graphql.GraphQLBoolean),
- description: 'When paginating forwards, are there more items?',
- },
- hasPreviousPage: {
- type: new _graphql.GraphQLNonNull(_graphql.GraphQLBoolean),
- description: 'When paginating backwards, are there more items?',
- },
- startCursor: {
- type: _graphql.GraphQLString,
- description: 'When paginating backwards, the cursor to continue.',
- },
- endCursor: {
- type: _graphql.GraphQLString,
- description: 'When paginating forwards, the cursor to continue.',
- },
- }),
- });
- /**
- * A type designed to be exposed as `PageInfo` over GraphQL.
- */
|