platform/packages/graphql/graphql_parser/example/example.dart
Tobe O 4e69153e3e Add 'packages/graphql/' from commit '33e2f86ba73d559197b6270df036256104726aca'
git-subtree-dir: packages/graphql
git-subtree-mainline: ac29392d7f
git-subtree-split: 33e2f86ba7
2020-02-15 18:22:07 -05:00

26 lines
671 B
Dart

import 'package:graphql_parser/graphql_parser.dart';
final String text = '''
{
project(name: "GraphQL") {
tagline
}
}
'''
.trim();
main() {
var tokens = scan(text);
var parser = Parser(tokens);
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.value); // GraphQL
var taglineField = projectField.selectionSet.selections.first.field;
print(taglineField.fieldName.name); // tagline
}