Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/absinthe/blueprint/document/fragment/named.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Absinthe.Blueprint.Document.Fragment.Named do
defstruct [
:name,
:type_condition,
:description,
selections: [],
directives: [],
source_location: nil,
Expand All @@ -22,6 +23,7 @@ defmodule Absinthe.Blueprint.Document.Fragment.Named do
directives: [Blueprint.Directive.t()],
errors: [Absinthe.Phase.Error.t()],
name: String.t(),
description: nil | String.t(),
selections: [Blueprint.Document.selection_t()],
schema_node: nil | Absinthe.Type.t(),
source_location: nil | Blueprint.SourceLocation.t(),
Expand Down
2 changes: 2 additions & 0 deletions lib/absinthe/blueprint/document/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Absinthe.Blueprint.Document.Operation do
defstruct [
:name,
:type,
:description,
current: false,
selections: [],
directives: [],
Expand All @@ -25,6 +26,7 @@ defmodule Absinthe.Blueprint.Document.Operation do
@type t :: %__MODULE__{
name: nil | String.t(),
type: :query | :mutation | :subscription,
description: nil | String.t(),
current: boolean,
directives: [Blueprint.Directive.t()],
selections: [Blueprint.Document.selection_t()],
Expand Down
3 changes: 3 additions & 0 deletions lib/absinthe/language/fragment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ defmodule Absinthe.Language.Fragment do
alias Absinthe.{Blueprint, Language}

defstruct name: nil,
description: nil,
type_condition: nil,
directives: [],
selection_set: nil,
loc: %{line: nil}

@type t :: %__MODULE__{
name: String.t(),
description: nil | String.t(),
type_condition: nil | Language.NamedType.t(),
directives: [Language.Directive.t()],
selection_set: Language.SelectionSet.t(),
Expand All @@ -21,6 +23,7 @@ defmodule Absinthe.Language.Fragment do
def convert(node, doc) do
%Blueprint.Document.Fragment.Named{
name: node.name,
description: node.description,
type_condition: Blueprint.Draft.convert(node.type_condition, doc),
selections: Blueprint.Draft.convert(node.selection_set.selections, doc),
directives: Blueprint.Draft.convert(node.directives, doc),
Expand Down
3 changes: 3 additions & 0 deletions lib/absinthe/language/operation_definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Absinthe.Language.OperationDefinition do

defstruct operation: nil,
name: nil,
description: nil,
variable_definitions: [],
directives: [],
selection_set: nil,
Expand All @@ -14,6 +15,7 @@ defmodule Absinthe.Language.OperationDefinition do
@type t :: %__MODULE__{
operation: :query | :mutation | :subscription,
name: nil | String.t(),
description: nil | String.t(),
variable_definitions: [Language.VariableDefinition.t()],
directives: [Language.Directive.t()],
selection_set: Language.SelectionSet.t(),
Expand All @@ -26,6 +28,7 @@ defmodule Absinthe.Language.OperationDefinition do
%Blueprint.Document.Operation{
name: node.name,
type: node.operation,
description: node.description,
directives: Absinthe.Blueprint.Draft.convert(node.directives, doc),
variable_definitions: Blueprint.Draft.convert(node.variable_definitions, doc),
selections: Blueprint.Draft.convert(node.selection_set.selections, doc),
Expand Down
20 changes: 12 additions & 8 deletions lib/absinthe/language/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ defmodule Absinthe.Language.Render do
end

defp render(%Absinthe.Language.OperationDefinition{} = op) do
if op.shorthand do
concat(operation_definition(op), block(render_list(op.selection_set.selections)))
else
glue(
concat([to_string(op.operation), operation_definition(op)]),
block(render_list(op.selection_set.selections))
)
end
doc =
if op.shorthand do
concat(operation_definition(op), block(render_list(op.selection_set.selections)))
else
glue(
concat([to_string(op.operation), operation_definition(op)]),
block(render_list(op.selection_set.selections))
)
end

description(doc, op.description)
end

defp render(%Absinthe.Language.Field{} = field) do
Expand Down Expand Up @@ -133,6 +136,7 @@ defmodule Absinthe.Language.Render do
directives(fragment.directives)
])
|> block(render_list(fragment.selection_set.selections))
|> description(fragment.description)
end

# Schema
Expand Down
2 changes: 2 additions & 0 deletions src/absinthe_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Definitions -> Definition : ['$1'].
Definitions -> Definition Definitions : ['$1'|'$2'].

Definition -> OperationDefinition : '$1'.
Definition -> DescriptionDefinition OperationDefinition : put_description('$2', '$1').
Definition -> Fragment : '$1'.
Definition -> DescriptionDefinition Fragment : put_description('$2', '$1').
Definition -> TypeDefinition : '$1'.

OperationType -> 'query' : '$1'.
Expand Down
Loading