platform/packages/graphql/graphql_parser/example/example.dart

27 lines
671 B
Dart
Raw Normal View History

2017-07-04 19:27:47 +00:00
import 'package:graphql_parser/graphql_parser.dart';
2017-01-22 23:15:53 +00:00
2018-08-05 00:44:41 +00:00
final String text = '''
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() {
2018-08-05 00:44:41 +00:00
var tokens = scan(text);
2019-08-08 02:24:19 +00:00
var parser = 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
2019-08-08 01:43:24 +00:00
print(projectField.arguments.first.value); // GraphQL
2017-07-04 19:27:47 +00:00
var taglineField = projectField.selectionSet.selections.first.field;
print(taglineField.fieldName.name); // tagline
2017-01-22 23:15:53 +00:00
}