2017-07-04 19:27:47 +00:00
|
|
|
import 'package:graphql_parser/graphql_parser.dart';
|
2017-01-22 23:15:53 +00:00
|
|
|
|
2017-07-03 15:37:35 +00:00
|
|
|
final String INPUT = '''
|
2017-01-22 23:15:53 +00:00
|
|
|
{
|
|
|
|
project(name: "GraphQL") {
|
|
|
|
tagline
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 15:53:19 +00:00
|
|
|
'''
|
|
|
|
.trim();
|
2017-01-22 23:15:53 +00:00
|
|
|
|
2017-02-05 23:08:03 +00:00
|
|
|
main() {
|
2017-07-03 15:37:35 +00:00
|
|
|
var tokens = scan(INPUT);
|
|
|
|
var parser = new Parser(tokens);
|
2017-07-04 19:27:47 +00:00
|
|
|
var doc = parser.parseDocument();
|
|
|
|
|
|
|
|
var operation = doc.definitions.first as OperationDefinitionContext;
|
|
|
|
|
|
|
|
var projectField = operation.selectionSet.selections.first.field;
|
|
|
|
print(projectField.fieldName.name); // project
|
|
|
|
print(projectField.arguments.first.name); // name
|
|
|
|
print(projectField.arguments.first.valueOrVariable.value.value); // GraphQL
|
|
|
|
|
|
|
|
var taglineField = projectField.selectionSet.selections.first.field;
|
|
|
|
print(taglineField.fieldName.name); // tagline
|
2017-01-22 23:15:53 +00:00
|
|
|
}
|