{"record":{"id":"d6fbdc2356b5ef79","repo":"instructure/canvas-lms","slug":"invalid-context-type","errorCode":null,"errorMessage":"invalid context type","messagePattern":"invalid context type","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/graphql_helpers/context_fetcher.rb","lineNumber":24,"sourceCode":"# This file is part of Canvas.\n#\n# Canvas is free software: you can redistribute it and/or modify it under\n# the terms of the GNU Affero General Public License as published by the Free\n# Software Foundation, version 3 of the License.\n#\n# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n\nmodule GraphQLHelpers::ContextFetcher\n  def context_fetcher(input, valid_context_types = [])\n    if valid_context_types.exclude?(input[:context_type])\n      raise GraphQL::ExecutionError, I18n.t(\"invalid context type\")\n    end\n\n    context =\n      begin\n        context_type = Object.const_get(input[:context_type])\n        context_type.find_by(id: input[:context_id])\n      rescue\n        raise GraphQL::ExecutionError, I18n.t(\"invalid context type\")\n      end\n    raise GraphQL::ExecutionError, I18n.t(\"context not found\") if context.nil?\n\n    context\n  end\nend\n","sourceCodeStart":6,"sourceCodeEnd":39,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/graphql_helpers/context_fetcher.rb#L6-L39","documentation":"GraphQLHelpers::ContextFetcher.context_fetcher first checks that input[:context_type] is among valid_context_types; if the client passes a context_type not in the allowlist, it raises GraphQL::ExecutionError 'invalid context type' before attempting lookup.","triggerScenarios":"A GraphQL mutation/query passing contextType like 'Group' or 'User' when only ['Course','Account'] are valid for that field, or a misspelled/nil context_type.","commonSituations":"Clients copying contextType values between fields with different allowlists; typos in casing ('course' vs 'Course'); forgetting to send contextType at all so it is nil.","solutions":["Pass context_type exactly matching an allowed value for the field (e.g. 'Course' or 'Account').","Check the field/mutation documentation for its valid_context_types list.","Ensure context_type is not nil — send it explicitly."],"exampleFix":"// before\nmutation { createConversationMessage(input: {contextType: \"Group\", ...}) }\n// after\nmutation { createConversationMessage(input: {contextType: \"Course\", ...}) }","handlingStrategy":"validation","validationCode":"const VALID = ['Course','Account']; if (!VALID.includes(input.contextType)) throw new Error(`contextType must be one of ${VALID.join(',')}`)","typeGuard":null,"tryCatchPattern":"try { await mutation(input) } catch (e) { if (e.message === 'invalid context type') { /* correct contextType and retry */ } else throw e }","preventionTips":["Use exact CamelCase model names for contextType","Read each field's valid_context_types","Never send nil contextType"],"tags":["graphql","validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}