UNPKG

@userlab/dx

Version:

Build efficient GraphQL backend

32 lines (31 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConnectionType = exports.PageInfoType = void 0; var graphql_1 = require("graphql"); exports.PageInfoType = new graphql_1.GraphQLObjectType({ name: 'PageInfo', fields: function () { return ({ hasNextPage: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, hasPreviousPage: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, startCursor: { type: graphql_1.GraphQLString }, endCursor: { type: graphql_1.GraphQLString }, }); }, }); var getConnectionType = function (objectType) { var edgeType = new graphql_1.GraphQLObjectType({ name: objectType.name + "Edge", fields: function () { return ({ node: { type: objectType }, cursor: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, }); }, }); var connectionType = new graphql_1.GraphQLObjectType({ name: objectType.name + "Connection", fields: function () { return ({ pageInfo: { type: new graphql_1.GraphQLNonNull(exports.PageInfoType) }, edges: { type: new graphql_1.GraphQLList(edgeType) }, }); }, }); return connectionType; }; exports.getConnectionType = getConnectionType;