Skip to content

Commit

Permalink
add directives parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
juancastillo0 committed Oct 25, 2021
1 parent 07bb75c commit d576118
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions gql/test/parser_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:gql/ast.dart";
import "package:gql/src/language/parser.dart";
import "package:source_span/source_span.dart";
import "package:test/test.dart";
Expand Down Expand Up @@ -102,6 +103,59 @@ void main() {
);
});

test("Directives parsing", () {
final doc = parseString("""
directive @onQuery on QUERY
directive @onMutation on MUTATION
directive @onSubscription on SUBSCRIPTION
directive @onField on FIELD
directive @onFragmentDefinition on FRAGMENT_DEFINITION
directive @onFragmentSpread on FRAGMENT_SPREAD
directive @onInlineFragment on INLINE_FRAGMENT
directive @onVariableDefinition on VARIABLE_DEFINITION
directive @onSchema on SCHEMA
directive @onScalar on SCALAR
directive @onObject on OBJECT
directive @onFieldDefinition on FIELD_DEFINITION
directive @onArgumentDefinition on ARGUMENT_DEFINITION
directive @onInterface on INTERFACE
directive @onUnion on UNION
directive @onEnum on ENUM
directive @onEnumValue on ENUM_VALUE
directive @onInputObject on INPUT_OBJECT
directive @onInputFieldDefinition on INPUT_FIELD_DEFINITION
""");

final map = Map.fromEntries(
doc.definitions.whereType<DirectiveDefinitionNode>().map((e) {
expect(e.locations.length, 1);
return MapEntry(e.name.value, e.locations.first);
}),
);

expect(map, {
"onQuery": DirectiveLocation.query,
"onMutation": DirectiveLocation.mutation,
"onSubscription": DirectiveLocation.subscription,
"onField": DirectiveLocation.field,
"onFragmentDefinition": DirectiveLocation.fragmentDefinition,
"onFragmentSpread": DirectiveLocation.fragmentSpread,
"onInlineFragment": DirectiveLocation.inlineFragment,
"onVariableDefinition": DirectiveLocation.variableDefinition,
"onSchema": DirectiveLocation.schema,
"onScalar": DirectiveLocation.scalar,
"onObject": DirectiveLocation.object,
"onFieldDefinition": DirectiveLocation.fieldDefinition,
"onArgumentDefinition": DirectiveLocation.argumentDefinition,
"onInterface": DirectiveLocation.interface,
"onUnion": DirectiveLocation.union,
"onEnum": DirectiveLocation.enumDefinition,
"onEnumValue": DirectiveLocation.enumValue,
"onInputObject": DirectiveLocation.inputObject,
"onInputFieldDefinition": DirectiveLocation.inputFieldDefinition,
});
});

test("Incomplete schema type extension", () {
expect(
() => parseString("extend schema"),
Expand Down

0 comments on commit d576118

Please sign in to comment.