Skip to content

Commit

Permalink
feat(Parser) make operation_name optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Oct 1, 2015
1 parent e4bf218 commit 86c3d6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/graphql/language/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class Parser < Parslet::Parser
selections.as(:selections)
}

rule(:operation_definition) { (unnamed_selections | named_operation_definition) }
rule(:operation_definition) { (unnamed_selections | typed_operation_definition) }
rule(:unnamed_selections) { selections.as(:unnamed_selections)}
rule(:named_operation_definition) {
rule(:typed_operation_definition) {
operation_type.as(:operation_type) >> space? >>
name.as(:name) >> space? >>
name.as(:name).maybe >> space? >>
operation_variable_definitions.maybe.as(:optional_variables).as(:variables) >> space? >>
directives.maybe.as(:optional_directives).as(:directives) >> space? >>
selections.as(:selections)
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/language/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
assert(parser.operation_definition.parse_with_debug(%|query personStuff {id, name, ...people, ... stuff}|), "named fetch")
assert(parser.operation_definition.parse_with_debug(%|query personStuff @flagDirective {id, name, ...people}|), "with a directive")
assert(parser.operation_definition.parse_with_debug(%|mutation changeStuff($stuff: Int = 1, $things: [SomeType]!) {id, name, ...people}|), "mutation with arguments")
assert(parser.operation_definition.parse_with_debug(%|mutation { id }|), "unnamed")
end

it 'parses fragment definitions' do
Expand Down

0 comments on commit 86c3d6d

Please sign in to comment.