Commit 00e709db authored by charlie ablett's avatar charlie ablett

Merge branch 'ajk-linked-graphql-docs-with-args' into 'master'

Linked GraphQL docs output

See merge request gitlab-org/gitlab!55944
parents 12476cb9 e2311e8a
...@@ -23,7 +23,11 @@ module Mutations ...@@ -23,7 +23,11 @@ module Mutations
argument :color, GraphQL::STRING_TYPE, argument :color, GraphQL::STRING_TYPE,
required: false, required: false,
default_value: Label::DEFAULT_COLOR, default_value: Label::DEFAULT_COLOR,
description: "The color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the CSS color names in https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords." description: <<~DESC
The color of the label given in 6-digit hex notation with leading '#' sign
(for example, `#FFAABB`) or one of the CSS color names
<https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords>.
DESC
authorize :admin_label authorize :admin_label
......
...@@ -7,57 +7,57 @@ module IssueResolverArguments ...@@ -7,57 +7,57 @@ module IssueResolverArguments
include LooksAhead include LooksAhead
argument :iid, GraphQL::STRING_TYPE, argument :iid, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'IID of the issue. For example, "1".' description: 'IID of the issue. For example, "1".'
argument :iids, [GraphQL::STRING_TYPE], argument :iids, [GraphQL::STRING_TYPE],
required: false, required: false,
description: 'List of IIDs of issues. For example, [1, 2].' description: 'List of IIDs of issues. For example, ["1", "2"].'
argument :label_name, [GraphQL::STRING_TYPE, null: true], argument :label_name, [GraphQL::STRING_TYPE, null: true],
required: false, required: false,
description: 'Labels applied to this issue.' description: 'Labels applied to this issue.'
argument :milestone_title, [GraphQL::STRING_TYPE, null: true], argument :milestone_title, [GraphQL::STRING_TYPE, null: true],
required: false, required: false,
description: 'Milestone applied to this issue.' description: 'Milestone applied to this issue.'
argument :author_username, GraphQL::STRING_TYPE, argument :author_username, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'Username of the author of the issue.' description: 'Username of the author of the issue.'
argument :assignee_username, GraphQL::STRING_TYPE, argument :assignee_username, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'Username of a user assigned to the issue.', description: 'Username of a user assigned to the issue.',
deprecated: { reason: 'Use `assigneeUsernames`', milestone: '13.11' } deprecated: { reason: 'Use `assigneeUsernames`', milestone: '13.11' }
argument :assignee_usernames, [GraphQL::STRING_TYPE], argument :assignee_usernames, [GraphQL::STRING_TYPE],
required: false, required: false,
description: 'Usernames of users assigned to the issue.' description: 'Usernames of users assigned to the issue.'
argument :assignee_id, GraphQL::STRING_TYPE, argument :assignee_id, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'ID of a user assigned to the issues, "none" and "any" values are supported.' description: 'ID of a user assigned to the issues, "none" and "any" values are supported.'
argument :created_before, Types::TimeType, argument :created_before, Types::TimeType,
required: false, required: false,
description: 'Issues created before this date.' description: 'Issues created before this date.'
argument :created_after, Types::TimeType, argument :created_after, Types::TimeType,
required: false, required: false,
description: 'Issues created after this date.' description: 'Issues created after this date.'
argument :updated_before, Types::TimeType, argument :updated_before, Types::TimeType,
required: false, required: false,
description: 'Issues updated before this date.' description: 'Issues updated before this date.'
argument :updated_after, Types::TimeType, argument :updated_after, Types::TimeType,
required: false, required: false,
description: 'Issues updated after this date.' description: 'Issues updated after this date.'
argument :closed_before, Types::TimeType, argument :closed_before, Types::TimeType,
required: false, required: false,
description: 'Issues closed before this date.' description: 'Issues closed before this date.'
argument :closed_after, Types::TimeType, argument :closed_after, Types::TimeType,
required: false, required: false,
description: 'Issues closed after this date.' description: 'Issues closed after this date.'
argument :search, GraphQL::STRING_TYPE, argument :search, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'Search query for issue title or description.' description: 'Search query for issue title or description.'
argument :types, [Types::IssueTypeEnum], argument :types, [Types::IssueTypeEnum],
as: :issue_types, as: :issue_types,
description: 'Filter issues by the given issue types.', description: 'Filter issues by the given issue types.',
required: false required: false
argument :not, Types::Issues::NegatedIssueFilterInputType, argument :not, Types::Issues::NegatedIssueFilterInputType,
description: 'List of negated params.', description: 'Negated arguments.',
prepare: ->(negated_args, ctx) { negated_args.to_h }, prepare: ->(negated_args, ctx) { negated_args.to_h },
required: false required: false
end end
......
---
title: Add missing parts of GraphQL schema to GraphQL documentation
merge_request: 55944
author:
type: changed
This diff is collapsed.
...@@ -18,7 +18,7 @@ WARNING: ...@@ -18,7 +18,7 @@ WARNING:
This API is in the process of being deprecated and considered unstable. This API is in the process of being deprecated and considered unstable.
The response payload may be subject to change or breakage The response payload may be subject to change or breakage
across GitLab releases. Please use the across GitLab releases. Please use the
[GraphQL API](graphql/reference/index.md#vulnerabilities) [GraphQL API](graphql/reference/index.md#queryvulnerabilities)
instead. instead.
Every API call to vulnerabilities must be [authenticated](README.md#authentication). Every API call to vulnerabilities must be [authenticated](README.md#authentication).
......
...@@ -10,7 +10,10 @@ module Types ...@@ -10,7 +10,10 @@ module Types
argument :not, NegatedEpicBoardIssueInputType, argument :not, NegatedEpicBoardIssueInputType,
required: false, required: false,
description: 'List of epic negated params. Warning: this argument is experimental and a subject to change in the future.' description: <<~DESC
Negated epic arguments.
Warning: this argument is experimental and a subject to change in the future.
DESC
argument :search, GraphQL::STRING_TYPE, argument :search, GraphQL::STRING_TYPE,
required: false, required: false,
......
...@@ -41,7 +41,7 @@ module Gitlab ...@@ -41,7 +41,7 @@ module Gitlab
parts = [ parts = [
"#{deprecated_in(format: :markdown)}.", "#{deprecated_in(format: :markdown)}.",
reason_text, reason_text,
replacement.then { |r| "Use: `#{r}`." if r } replacement.then { |r| "Use: [`#{r}`](##{r.downcase.tr('.', '')})." if r }
].compact ].compact
case context case context
......
This diff is collapsed.
...@@ -24,6 +24,7 @@ module Gitlab ...@@ -24,6 +24,7 @@ module Gitlab
@layout = Haml::Engine.new(File.read(template)) @layout = Haml::Engine.new(File.read(template))
@parsed_schema = GraphQLDocs::Parser.new(schema.graphql_definition, {}).parse @parsed_schema = GraphQLDocs::Parser.new(schema.graphql_definition, {}).parse
@schema = schema @schema = schema
@seen = Set.new
end end
def contents def contents
...@@ -37,6 +38,16 @@ module Gitlab ...@@ -37,6 +38,16 @@ module Gitlab
FileUtils.mkdir_p(@output_dir) FileUtils.mkdir_p(@output_dir)
File.write(filename, contents) File.write(filename, contents)
end end
private
def seen_type?(name)
@seen.include?(name)
end
def seen_type!(name)
@seen << name
end
end end
end end
end end
......
...@@ -26,17 +26,81 @@ ...@@ -26,17 +26,81 @@
The `Query` type contains the API's top-level entry points for all executable queries. The `Query` type contains the API's top-level entry points for all executable queries.
\ \
- sorted_by_name(queries).each do |query| - fields_of('Query').each do |field|
= render_name_and_description(query, owner: 'Query') = render_full_field(field, heading_level: 3, owner: 'Query')
\ \
= render_return_type(query)
- unless query[:arguments].empty? :plain
~ "#### Arguments\n" ## `Mutation` type
~ "| Name | Type | Description |"
~ "| ---- | ---- | ----------- |" The `Mutation` type contains all the mutations you can execute.
- sorted_by_name(query[:arguments]).each do |argument|
= render_field(argument, query[:type][:name]) All mutations receive their arguments in a single input object named `input`, and all mutations
\ support at least a return field `errors` containing a list of error messages.
All input objects may have a `clientMutationId: String` field, identifying the mutation.
For example:
```graphql
mutation($id: NoteableID!, $body: String!) {
createNote(input: { noteableId: $id, body: $body }) {
errors
}
}
```
\
- mutations.each do |field|
= render_full_field(field, heading_level: 3, owner: 'Mutation')
\
:plain
## Connections
Some types in our schema are `Connection` types - they represent a paginated
collection of edges between two nodes in the graph. These follow the
[Relay cursor connections specification](https://relay.dev/graphql/connections.htm).
### Pagination arguments {#connection-pagination-arguments}
All connection fields support the following pagination arguments:
| Name | Type | Description |
|------|------|-------------|
| `after` | [`String`](#string) | Returns the elements in the list that come after the specified cursor. |
| `before` | [`String`](#string) | Returns the elements in the list that come before the specified cursor. |
| `first` | [`Int`](#int) | Returns the first _n_ elements from the list. |
| `last` | [`Int`](#int) | Returns the last _n_ elements from the list. |
Since these arguments are common to all connection fields, they are not repeated for each connection.
### Connection fields
All connections have at least the following fields:
| Name | Type | Description |
|------|------|-------------|
| `pageInfo` | [`PageInfo!`](#pageinfo) | Pagination information. |
| `edges` | `[edge!]` | The edges. |
| `nodes` | `[item!]` | The items in the current page. |
The precise type of `Edge` and `Item` depends on the kind of connection. A
[`UserConnection`](#userconnection) will have nodes that have the type
[`[User!]`](#user), and edges that have the type [`UserEdge`](#useredge).
### Connection types
Some of the types in the schema exist solely to model connections. Each connection
has a distinct, named type, with a distinct named edge type. These are listed separately
below.
\
- connection_object_types.each do |type|
= render_name_and_description(type, level: 4)
\
= render_object_fields(type[:fields], owner: type, level_bump: 1)
\
:plain :plain
## Object types ## Object types
...@@ -44,22 +108,20 @@ ...@@ -44,22 +108,20 @@
Object types represent the resources that the GitLab GraphQL API can return. Object types represent the resources that the GitLab GraphQL API can return.
They contain _fields_. Each field has its own type, which will either be one of the They contain _fields_. Each field has its own type, which will either be one of the
basic GraphQL [scalar types](https://graphql.org/learn/schema/#scalar-types) basic GraphQL [scalar types](https://graphql.org/learn/schema/#scalar-types)
(e.g.: `String` or `Boolean`) or other object types. (e.g.: `String` or `Boolean`) or other object types. Fields may have arguments.
Fields with arguments are exactly like top-level queries, and are listed beneath
the table of fields for each object type.
For more information, see For more information, see
[Object Types and Fields](https://graphql.org/learn/schema/#object-types-and-fields) [Object Types and Fields](https://graphql.org/learn/schema/#object-types-and-fields)
on `graphql.org`. on `graphql.org`.
\ \
- objects.each do |type| - object_types.each do |type|
- unless type[:fields].empty? = render_name_and_description(type)
= render_name_and_description(type) \
\ = render_object_fields(type[:fields], owner: type)
~ "| Field | Type | Description |" \
~ "| ----- | ---- | ----------- |"
- sorted_by_name(type[:fields]).each do |field|
= render_field(field, type[:name])
\
:plain :plain
## Enumeration types ## Enumeration types
...@@ -73,14 +135,13 @@ ...@@ -73,14 +135,13 @@
\ \
- enums.each do |enum| - enums.each do |enum|
- unless enum[:values].empty? = render_name_and_description(enum)
= render_name_and_description(enum) \
\ ~ "| Value | Description |"
~ "| Value | Description |" ~ "| ----- | ----------- |"
~ "| ----- | ----------- |" - enum[:values].each do |value|
- sorted_by_name(enum[:values]).each do |value| = render_enum_value(enum, value)
= render_enum_value(enum, value) \
\
:plain :plain
## Scalar types ## Scalar types
...@@ -133,7 +194,7 @@ ...@@ -133,7 +194,7 @@
### Interfaces ### Interfaces
\ \
- graphql_interface_types.each do |type| - interfaces.each do |type|
= render_name_and_description(type, level: 4) = render_name_and_description(type, level: 4)
\ \
Implementations: Implementations:
...@@ -141,8 +202,21 @@ ...@@ -141,8 +202,21 @@
- type[:implemented_by].each do |type_name| - type[:implemented_by].each do |type_name|
~ "- [`#{type_name}`](##{type_name.downcase})" ~ "- [`#{type_name}`](##{type_name.downcase})"
\ \
~ "| Field | Type | Description |" = render_object_fields(type[:fields], owner: type, level_bump: 1)
~ "| ----- | ---- | ----------- |" \
- sorted_by_name(type[:fields] + type[:connections]).each do |field|
= render_field(field, type[:name]) :plain
## Input types
Types that may be used as arguments (all scalar types may also
be used as arguments).
Only general use input types are listed here. For mutation input types,
see the associated mutation type above.
\
- input_types.each do |type|
= render_name_and_description(type)
\
= render_argument_table(3, type[:input_fields], type[:name])
\ \
...@@ -164,7 +164,7 @@ RSpec.describe ::Gitlab::Graphql::Deprecation do ...@@ -164,7 +164,7 @@ RSpec.describe ::Gitlab::Graphql::Deprecation do
context 'when the context is :inline' do context 'when the context is :inline' do
it 'renders on one line' do it 'renders on one line' do
expectation = '**Deprecated** in 10.10. This was renamed. Use: `X.y`.' expectation = '**Deprecated** in 10.10. This was renamed. Use: [`X.y`](#xy).'
expect(deprecation.markdown).to eq(expectation) expect(deprecation.markdown).to eq(expectation)
expect(deprecation.markdown(context: :inline)).to eq(expectation) expect(deprecation.markdown(context: :inline)).to eq(expectation)
...@@ -177,7 +177,7 @@ RSpec.describe ::Gitlab::Graphql::Deprecation do ...@@ -177,7 +177,7 @@ RSpec.describe ::Gitlab::Graphql::Deprecation do
WARNING: WARNING:
**Deprecated** in 10.10. **Deprecated** in 10.10.
This was renamed. This was renamed.
Use: `X.y`. Use: [`X.y`](#xy).
MD MD
expect(deprecation.markdown(context: :block)).to eq(expectation) expect(deprecation.markdown(context: :block)).to eq(expectation)
......
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