diff --git a/graphql_parser/lib/src/language/parser.dart b/graphql_parser/lib/src/language/parser.dart index 7724b9c1..810bf8ab 100644 --- a/graphql_parser/lib/src/language/parser.dart +++ b/graphql_parser/lib/src/language/parser.dart @@ -16,8 +16,9 @@ class Parser { Token get current => _current; - bool next(TokenType type) { - if (peek()?.type == type) { + bool next(TokenType type, {Iterable exclude}) { + var tok = peek(); + if (tok?.type == type && exclude?.contains(tok.span.text) != true) { _current = tokens[++_index]; return true; } @@ -27,7 +28,6 @@ class Parser { bool nextName(String name) { var tok = peek(); - if (tok?.type == TokenType.NAME && tok.span.text == name) { return next(TokenType.NAME); } @@ -140,7 +140,7 @@ class Parser { FragmentSpreadContext parseFragmentSpread() { if (next(TokenType.ELLIPSIS)) { var ELLIPSIS = current; - if (next(TokenType.NAME)) { + if (next(TokenType.NAME, exclude: ['on'])) { var NAME = current; return new FragmentSpreadContext(ELLIPSIS, NAME) ..directives.addAll(parseDirectives()); diff --git a/graphql_parser/test/selection_set_test.dart b/graphql_parser/test/selection_set_test.dart index 34a8bc6f..438db5bd 100644 --- a/graphql_parser/test/selection_set_test.dart +++ b/graphql_parser/test/selection_set_test.dart @@ -73,10 +73,13 @@ class _IsSelectionSet extends Matcher { bool matches(item, Map matchState) { var set = item is SelectionSetContext ? item : parseSelectionSet(item.toString()); - print('Item: $set has ${set.selections.length} selection(s):'); - for (var s in set.selections) { - print(' * $s (${s.span.text})'); - } + + // if (set != null) { + // print('Item: $set has ${set.selections.length} selection(s):'); + // for (var s in set.selections) { + // print(' * $s (${s.span.text})'); + // } + // } if (set == null) return false; if (set.selections.length != selections.length) return false;