Commit edf074f7 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'ld-graphql-version-bump-gem-for-argument-deprecations' into 'master'

GraphQL: Enable arguments to be marked as deprecated in schema

See merge request gitlab-org/gitlab!45229
parents 87108e89 adcfba95
...@@ -6,7 +6,6 @@ module Types ...@@ -6,7 +6,6 @@ module Types
def initialize(*args, **kwargs, &block) def initialize(*args, **kwargs, &block)
kwargs = gitlab_deprecation(kwargs) kwargs = gitlab_deprecation(kwargs)
kwargs.delete(:deprecation_reason)
super(*args, **kwargs, &block) super(*args, **kwargs, &block)
end end
......
...@@ -10,7 +10,7 @@ module GitlabStyleDeprecations ...@@ -10,7 +10,7 @@ module GitlabStyleDeprecations
def gitlab_deprecation(kwargs) def gitlab_deprecation(kwargs)
if kwargs[:deprecation_reason].present? if kwargs[:deprecation_reason].present?
raise ArgumentError, 'Use `deprecated` property instead of `deprecation_reason`. ' \ 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 end
deprecation = kwargs.delete(:deprecated) 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 ...@@ -490,15 +490,18 @@ def foo
end end
``` ```
## Deprecating fields and enum values ## Deprecating fields, arguments, and enum values
The GitLab GraphQL API is versionless, which means we maintain backwards The GitLab GraphQL API is versionless, which means we maintain backwards
compatibility with older versions of the API with every change. Rather compatibility with older versions of the API with every change.
than removing a field or [enum value](#enums), we need to _deprecate_ it instead.
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 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). 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: The value of the property is a `Hash` of:
- `reason` - Reason for the deprecation. - `reason` - Reason for the deprecation.
...@@ -518,14 +521,15 @@ is appended to the `description`. ...@@ -518,14 +521,15 @@ is appended to the `description`.
### Deprecation reason style guide ### Deprecation reason style guide
Where the reason for deprecation is due to the field or enum value being Where the reason for deprecation is due to the field, argument, or enum value being
replaced, the `reason` must be: replaced, the `reason` must indicate the replacement. For example, the
following is a `reason` for a replaced field:
```plaintext ```plaintext
Use `otherFieldName` Use `otherFieldName`
``` ```
Example: Examples:
```ruby ```ruby
field :designs, ::Types::DesignManagement::DesignCollectionType, null: true, field :designs, ::Types::DesignManagement::DesignCollectionType, null: true,
...@@ -544,8 +548,8 @@ module Types ...@@ -544,8 +548,8 @@ module Types
end end
``` ```
If the field is not being replaced by another field, a descriptive If the field, argument, or enum value being deprecated is not being replaced,
deprecation `reason` should be given. a descriptive deprecation `reason` should be given.
See also [Aliasing and deprecating mutations](#aliasing-and-deprecating-mutations). See also [Aliasing and deprecating mutations](#aliasing-and-deprecating-mutations).
...@@ -594,7 +598,7 @@ end ...@@ -594,7 +598,7 @@ end
``` ```
Enum values can be deprecated using the 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 ### Defining GraphQL enums dynamically from Rails enums
...@@ -1567,7 +1571,7 @@ mount_aliased_mutation 'BarMutation', Mutations::FooMutation ...@@ -1567,7 +1571,7 @@ mount_aliased_mutation 'BarMutation', Mutations::FooMutation
``` ```
This allows us to rename a mutation and continue to support the old name, 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. argument.
Example: 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 ...@@ -6,7 +6,7 @@ RSpec.shared_examples 'Gitlab-style deprecations' do
expect { subject(deprecation_reason: 'foo') }.to raise_error( expect { subject(deprecation_reason: 'foo') }.to raise_error(
ArgumentError, ArgumentError,
'Use `deprecated` property instead of `deprecation_reason`. ' \ '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 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