Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| import { isObject } from "lodash" | |
| import { invariant, missingArgument } from "@/utilities" | |
| const Sort = new GqlEnum({ | |
| name: `Sort`, | |
| description: `Sort options for OrderBy`, | |
| values: { | |
| asc: {}, | |
| desc: {} | |
| } | |
| }) | |
| export function createOrder(type) { | |
| invariant(isObject(type), missingArgument({ type }, `object`)) | |
| const FieldsEnum = new GqlEnum({ | |
| name: `${type._typeConfig.name.toLowerCase()}OrderByFields`, | |
| description: `A list of field names that this type can be ordered by.`, | |
| values: Object.entries(type._typeConfig.fields(true)) | |
| .filter(([name, values]) => !!values.sortable) | |
| .reduce((hash, [name, values]) => { | |
| hash[`${name}`] = {} | |
| return hash | |
| }, {}) | |
| }) | |
| return new GqlInput({ | |
| name: `${type._typeConfig.name.toLowerCase()}OrderBy`, | |
| description: `Sorts the results ordered by the selected field.`, | |
| fields: () => ({ | |
| field: { | |
| type: new GqlNonNull(FieldsEnum), | |
| description: `The field by which to sort the results. (Required)` | |
| }, | |
| sort: { | |
| type: Sort, | |
| defaultValue: `asc`, | |
| description: `The direction by which to sort the results. (Optional, defaults to ascending)` | |
| } | |
| }) | |
| }) | |
| } |