Commit adcfba95 authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Jan Provaznik

Support schema-deprecated arguments for GraphQL

The newer version of the graphql gem updated in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53697 supports
marking arguments as deprecated within the schema
(https://github.com/rmosolgo/graphql-ruby/pull/3015).

Previously, deprecated arguments were only marked as such in their
description.

This change enables them to be fully marked as deprecated in the schema,
and therefore introspection queries.
parent b0edafe7
......@@ -6,7 +6,6 @@ module Types
def initialize(*args, **kwargs, &block)
kwargs = gitlab_deprecation(kwargs)
kwargs.delete(:deprecation_reason)
super(*args, **kwargs, &block)
end
......
......@@ -10,7 +10,7 @@ module GitlabStyleDeprecations
def gitlab_deprecation(kwargs)
if kwargs[:deprecation_reason].present?
raise ArgumentError, 'Use `deprecated` property instead of `deprecation_reason`. ' \
'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields-and-enum-values'
'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields-arguments-and-enum-values'
end
deprecation = kwargs.delete(:deprecated)
......
---
title: Mark `startDate` and `endDate` arguments as deprecated in the GraphQL schema for `Project.milestones` and `Group.milestones`
(FOSS and EE), and `Project.iterations`, `Project.milestones`, `Group.epic`, `Group.epics`, `Group.iterations`, `Group.milestones`,
`BoardEpic.children`, and `Epic.children` fields (EE-only). Previously these arguments were marked as deprecated only in their descriptions
merge_request: 45229
author:
type: changed
......@@ -490,15 +490,18 @@ def foo
end
```
## Deprecating fields and enum values
## Deprecating fields, arguments, and enum values
The GitLab GraphQL API is versionless, which means we maintain backwards
compatibility with older versions of the API with every change. Rather
than removing a field or [enum value](#enums), we need to _deprecate_ it instead.
compatibility with older versions of the API with every change.
Rather than removing fields, arguments, or [enum values](#enums), they
must be _deprecated_ instead.
The deprecated parts of the schema can then be removed in a future release
in accordance with the [GitLab deprecation process](../api/graphql/index.md#deprecation-process).
Fields and enum values are deprecated using the `deprecated` property.
Fields, arguments, and enum values are deprecated using the `deprecated` property.
The value of the property is a `Hash` of:
- `reason` - Reason for the deprecation.
......@@ -518,14 +521,15 @@ is appended to the `description`.
### Deprecation reason style guide
Where the reason for deprecation is due to the field or enum value being
replaced, the `reason` must be:
Where the reason for deprecation is due to the field, argument, or enum value being
replaced, the `reason` must indicate the replacement. For example, the
following is a `reason` for a replaced field:
```plaintext
Use `otherFieldName`
```
Example:
Examples:
```ruby
field :designs, ::Types::DesignManagement::DesignCollectionType, null: true,
......@@ -544,8 +548,8 @@ module Types
end
```
If the field is not being replaced by another field, a descriptive
deprecation `reason` should be given.
If the field, argument, or enum value being deprecated is not being replaced,
a descriptive deprecation `reason` should be given.
See also [Aliasing and deprecating mutations](#aliasing-and-deprecating-mutations).
......@@ -594,7 +598,7 @@ end
```
Enum values can be deprecated using the
[`deprecated` keyword](#deprecating-fields-and-enum-values).
[`deprecated` keyword](#deprecating-fields-arguments-and-enum-values).
### Defining GraphQL enums dynamically from Rails enums
......@@ -1567,7 +1571,7 @@ mount_aliased_mutation 'BarMutation', Mutations::FooMutation
```
This allows us to rename a mutation and continue to support the old name,
when coupled with the [`deprecated`](#deprecating-fields-and-enum-values)
when coupled with the [`deprecated`](#deprecating-fields-arguments-and-enum-values)
argument.
Example:
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::BaseArgument do
include_examples 'Gitlab-style deprecations' do
let_it_be(:field) do
Types::BaseField.new(name: 'field', type: String, null: true)
end
let(:base_args) { { name: 'test', type: String, required: false, owner: field } }
def subject(args = {})
described_class.new(**base_args.merge(args))
end
end
end
......@@ -6,7 +6,7 @@ RSpec.shared_examples 'Gitlab-style deprecations' do
expect { subject(deprecation_reason: 'foo') }.to raise_error(
ArgumentError,
'Use `deprecated` property instead of `deprecation_reason`. ' \
'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields-and-enum-values'
'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields-arguments-and-enum-values'
)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment