Introduce new GraphQL mutation to validate devfile

Issue: GraphQL: Add endpoint to validate a devfile (#410907 - closed) • Omar Nasser • 18.4

What does this MR do and why?

The workspaces create form should validate a devfile before a user submits the form. To achieve this, we create a GraphQL mutation which will take devfile(full content of the devfile) and return a list of errors if applicable.

References

Fixes GraphQL: Add endpoint to validate a devfile (#410907 - closed) • Omar Nasser • 18.4

Screenshots or screen recordings

N/A


How to set up and validate locally

  1. Start GDK: gdk start
  2. Go to: gdk.test:3000/-/graphql-explorer
  3. The following mutations are used for testing

Mutations

mutation DevfileValid{
  devfileValidate(input: {devfileYaml: "schemaVersion: \"2.2.0\"\ncomponents:\n  - name: development-environment\n    attributes:\n      gl/inject-editor: true\n    container:\n      image: \"registry.gitlab.com/gitlab-org/gitlab-build-images/workspaces/ubuntu-24.04:20250414234733-golang-1.23-node-23.9-yarn-1.22-ruby-3.4.2-rust-1.85-php-8.4.5-java-21.0.6-python-3.13-docker-27.5.1@sha256:3b3fb1374084a20349019b88302fcc8ace1a3de5ab09465668d09f95a0eaa34b\""}) {
    errors
    valid
  }
}

mutation DevfileSingleError{
  devfileValidate(input: {devfileYaml: "schemaVersion:2.2.1"}) {
    errors
    valid
  }
}

mutation DevfileMultipleErrors{
  devfileValidate(
    input: {
    	devfileYaml: "schemaVersion: 2.2.0\ncomponents:\n  - name: gl-tooling-container\n    container:\n      endpoints:\n      - name: gl-http-3000"
  	}
  ) {
    valid
    errors
  }
}

Response

# DevfileValid
{
  "data": {
    "devfileValidate": {
      "errors": [],
      "valid": true
    }
  },
  "correlationId": "01K3GEGR41CB1KN4TYFTW725AB"
}

# Single Error
{
  "data": {
    "devfileValidate": {
      "errors": [
        "Devfile yaml parse failed: Devfile YAML could not be parsed: YAML parsing resulted in 'String' type instead of 'Hash'"
      ],
      "valid": false
    }
  },
  "correlationId": "01K3GERH54GES7ZCCWKHP91VNG"
}

# Multiple Error

{
  "data": {
    "devfileValidate": {
      "valid": false,
      "errors": [
        "Devfile restrictions failed: Component name 'gl-tooling-container' must not start with 'gl-'",
        "No component has 'gl/inject-editor' attribute",
        "Endpoint name 'gl-http-3000' of component 'gl-tooling-container' must not start with 'gl-'"
      ]
    }
  },
  "correlationId": "01K3GETNSB2EJZYMG8H6S2KSBF"
}

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #410907 (closed)

Edited by Omar Nasser

Merge request reports

Loading