UNPKG

graphile-build

Version:

Build a GraphQL schema from plugins

39 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PageInfoStartEndCursorPlugin = void 0; require("graphile-config"); const version_ts_1 = require("../version.js"); exports.PageInfoStartEndCursorPlugin = { name: "PageInfoStartEndCursorPlugin", description: "Add startCursor/endCursor to the PageInfo type", version: version_ts_1.version, schema: { hooks: { GraphQLObjectType_fields(fields, build, context) { const { extend, getOutputTypeByName, inflection, graphql: { GraphQLString }, } = build; const { Self, fieldWithHooks } = context; if (Self.name !== inflection.builtin("PageInfo")) { return fields; } const Cursor = getOutputTypeByName(inflection.builtin("Cursor")) ?? GraphQLString; return extend(fields, { startCursor: fieldWithHooks({ isPageInfoStartCursorField: true, fieldName: "startCursor", }, () => ({ description: build.wrapDescription("When paginating backwards, the cursor to continue.", "field"), type: Cursor, })), endCursor: fieldWithHooks({ isPageInfoEndCursorField: true, fieldName: "endCursor", }, () => ({ description: build.wrapDescription("When paginating forwards, the cursor to continue.", "field"), type: Cursor, })), }, `Adding startCursor/endCursor to ${Self.name}`); }, }, }, }; //# sourceMappingURL=PageInfoStartEndCursorPlugin.js.map