Parse "subscription", also prepare for type system syntax

This commit is contained in:
Tobe O 2019-03-29 14:32:31 -04:00
parent 943a3cb53b
commit b259c2c5b8
7 changed files with 20 additions and 4 deletions

View file

@ -1,3 +1,9 @@
import 'node.dart'; import 'node.dart';
abstract class DefinitionContext extends Node {} abstract class DefinitionContext extends Node {}
abstract class ExecutableDefinitionContext extends DefinitionContext {}
abstract class TypeSystemDefinitionContext extends DefinitionContext {}
abstract class TypeSystemExtensionContext extends DefinitionContext {}

View file

@ -5,7 +5,7 @@ import 'package:source_span/source_span.dart';
import 'selection_set.dart'; import 'selection_set.dart';
import 'type_condition.dart'; import 'type_condition.dart';
class FragmentDefinitionContext extends DefinitionContext { class FragmentDefinitionContext extends ExecutableDefinitionContext {
final Token FRAGMENT, NAME, ON; final Token FRAGMENT, NAME, ON;
final TypeConditionContext typeCondition; final TypeConditionContext typeCondition;
final List<DirectiveContext> directives = []; final List<DirectiveContext> directives = [];

View file

@ -6,7 +6,7 @@ import 'directive.dart';
import 'selection_set.dart'; import 'selection_set.dart';
import 'variable_definitions.dart'; import 'variable_definitions.dart';
class OperationDefinitionContext extends DefinitionContext { class OperationDefinitionContext extends ExecutableDefinitionContext {
final Token TYPE, NAME; final Token TYPE, NAME;
final VariableDefinitionsContext variableDefinitions; final VariableDefinitionsContext variableDefinitions;
final List<DirectiveContext> directives = []; final List<DirectiveContext> directives = [];
@ -14,13 +14,18 @@ class OperationDefinitionContext extends DefinitionContext {
bool get isMutation => TYPE?.text == 'mutation'; bool get isMutation => TYPE?.text == 'mutation';
bool get isSubscription => TYPE?.text == 'subscription';
bool get isQuery => TYPE?.text == 'query' || TYPE == null; bool get isQuery => TYPE?.text == 'query' || TYPE == null;
String get name => NAME?.text; String get name => NAME?.text;
OperationDefinitionContext( OperationDefinitionContext(
this.TYPE, this.NAME, this.variableDefinitions, this.selectionSet) { this.TYPE, this.NAME, this.variableDefinitions, this.selectionSet) {
assert(TYPE == null || TYPE.text == 'query' || TYPE.text == 'mutation'); assert(TYPE == null ||
TYPE.text == 'query' ||
TYPE.text == 'mutation' ||
TYPE.text == 'subscription');
} }
@override @override

View file

@ -29,6 +29,7 @@ final Map<Pattern, TokenType> _patterns = {
')': TokenType.RPAREN, ')': TokenType.RPAREN,
'fragment': TokenType.FRAGMENT, 'fragment': TokenType.FRAGMENT,
'mutation': TokenType.MUTATION, 'mutation': TokenType.MUTATION,
'subscription': TokenType.SUBSCRIPTION,
'on': TokenType.ON, 'on': TokenType.ON,
'query': TokenType.QUERY, 'query': TokenType.QUERY,
'null': TokenType.NULL, 'null': TokenType.NULL,

View file

@ -61,7 +61,9 @@ class Parser {
if (selectionSet != null) if (selectionSet != null)
return new OperationDefinitionContext(null, null, null, selectionSet); return new OperationDefinitionContext(null, null, null, selectionSet);
else { else {
if (next(TokenType.MUTATION) || next(TokenType.QUERY)) { if (next(TokenType.MUTATION) ||
next(TokenType.QUERY) ||
next(TokenType.SUBSCRIPTION)) {
var TYPE = current; var TYPE = current;
Token NAME = next(TokenType.NAME) ? current : null; Token NAME = next(TokenType.NAME) ? current : null;
var variables = parseVariableDefinitions(); var variables = parseVariableDefinitions();

View file

@ -15,6 +15,7 @@ enum TokenType {
FRAGMENT, FRAGMENT,
MUTATION, MUTATION,
SUBSCRIPTION,
ON, ON,
QUERY, QUERY,

View file

@ -43,6 +43,7 @@ void main() {
}); });
} }
@graphQLClass
enum RomanceLanguage { enum RomanceLanguage {
SPANISH, SPANISH,
FRANCE, FRANCE,