{"record":{"id":"d74c5e7bcb8bd8e3","repo":"gitlabhq/gitlabhq","slug":"orderby-parameter-must-contain-one-key-value-pair","errorCode":null,"errorMessage":"orderBy parameter must contain one key-value pair.","messagePattern":"orderBy parameter must contain one key-value pair\\.","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/types/deployments_order_by_input_type.rb","lineNumber":19,"sourceCode":"# frozen_string_literal: true\n\nmodule Types\n  class DeploymentsOrderByInputType < BaseInputObject\n    graphql_name 'DeploymentsOrderByInput'\n    description 'Values for ordering deployments by a specific field'\n\n    argument :created_at,\n      Types::SortDirectionEnum,\n      required: false,\n      description: 'Order by Created time.'\n\n    argument :finished_at,\n      Types::SortDirectionEnum,\n      required: false,\n      description: 'Order by Finished time.'\n\n    def prepare\n      raise GraphQL::ExecutionError, 'orderBy parameter must contain one key-value pair.' unless to_h.size == 1\n\n      super\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/gitlabhq/gitlabhq/blob/55ee20384a1f55cb0e362dee1d07149613b1b9bf/app/graphql/types/deployments_order_by_input_type.rb#L1-L25","documentation":"Types::DeploymentsOrderByInputType#prepare (app/graphql/types/deployments_order_by_input_type.rb:19) raises GraphQL::ExecutionError unless the input object hashes to exactly one key. The type exposes createdAt and finished_at sort directions, and the deployments query plan supports ordering by only one of them at a time. Passing both or neither aborts the query with 'orderBy parameter must contain one key-value pair.'.","triggerScenarios":"Querying project/group deployments with orderBy: {} (no keys) or orderBy: {createdAt: DESC, finishedAt: ASC} (two keys). Programmatic clients that build the orderBy dict from a list of sort criteria easily emit multi-key objects.","commonSituations":"Frontend tables that map several column sorts into one GraphQL call; copying examples from issue/MR queries whose orderBy types accept multiple keys; defaulting orderBy to an empty object when the user has no sort selected.","solutions":["Pass exactly one key: orderBy: {createdAt: DESC} or orderBy: {finishedAt: ASC}.","In code, pick the first active sort criterion and send only it: const orderBy = { [firstSort.field]: firstSort.dir }.","When no sorting is requested, omit the orderBy argument instead of sending {}.","If combined sorting is a real requirement, propose a schema change on the GitLab side; the current type intentionally forbids it."],"exampleFix":"# before\nquery($orderBy: DeploymentsOrderByInput) { deployments(orderBy: $orderBy) { ... } }\n# variables: {\"orderBy\": {\"createdAt\": \"DESC\", \"finishedAt\": \"ASC\"}}\n\n# after\n# variables: {\"orderBy\": {\"createdAt\": \"DESC\"}}","handlingStrategy":"validation","validationCode":"// JS: build orderBy from a single active sort\nconst orderBy = sorts.length === 1 ? { [sorts[0].field]: sorts[0].dir } : undefined;\nconst variables = { ...(orderBy && { orderBy }) };","typeGuard":"function isValidOrderBy(o) {\n  return o == null || (Object.keys(o).length === 1 && ['createdAt', 'finishedAt'].includes(Object.keys(o)[0]));\n}","tryCatchPattern":null,"preventionTips":["Model the sort as a single (field, direction) pair in client state, not a dict.","Add a client-side assertion Object.keys(orderBy).length === 1 before fetching.","Remember other GitLab orderBy types have different rules — do not generalize."],"tags":["graphql","input-validation","sorting","deployments"],"backgroundTag":"graphql-argument-validation","analyzedSha":"55ee20384a1f55cb0e362dee1d07149613b1b9bf","analyzedAt":"2026-08-21T14:22:27.782Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}