UNPKG

graphile-build-pg

Version:

Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build

42 lines (41 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var PgConnectionArgOrderByDefaultValue = function PgConnectionArgOrderByDefaultValue(builder) { builder.hook("GraphQLObjectType:fields:field:args", (args, build, context) => { const { extend, getTypeByName, pgGetGqlTypeByTypeIdAndModifier, inflection } = build; const { scope: { fieldName, isPgFieldConnection, pgFieldIntrospection: table }, Self } = context; if (!isPgFieldConnection || !table || table.kind !== "class" || !table.namespace || !table.isSelectable || !args.orderBy) { return args; } const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null); const tableTypeName = TableType.name; const TableOrderByType = getTypeByName(inflection.orderByType(tableTypeName)); if (!TableOrderByType) { return args; } const primaryKeyAsc = inflection.builtin("PRIMARY_KEY_ASC"); const defaultValueEnum = TableOrderByType.getValues().find(v => v.name === primaryKeyAsc) || TableOrderByType.getValues()[0]; return extend(args, { orderBy: extend(args.orderBy, { defaultValue: defaultValueEnum && [defaultValueEnum.value] }, `Adding defaultValue to orderBy for field '${fieldName}' of '${Self.name}'`) }); }, ["PgConnectionArgOrderByDefaultValue"]); }; exports.default = PgConnectionArgOrderByDefaultValue; //# sourceMappingURL=PgConnectionArgOrderByDefaultValue.js.map