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';
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 'type_condition.dart';
class FragmentDefinitionContext extends DefinitionContext {
class FragmentDefinitionContext extends ExecutableDefinitionContext {
final Token FRAGMENT, NAME, ON;
final TypeConditionContext typeCondition;
final List<DirectiveContext> directives = [];

View file

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

View file

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

View file

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

View file

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

View file

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