Skip to content

Commit 39473eb

Browse files
committed
initial commit
0 parents  commit 39473eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+18364
-0
lines changed

Diff for: .gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Files and directories created by pub
2+
.dart_tool/
3+
.packages
4+
# Remove the following pattern if you wish to check in your lock file
5+
pubspec.lock
6+
7+
# Conventional directory for build outputs
8+
build/
9+
10+
# Directory created by dartdoc
11+
doc/api/
12+
13+
14+
.idea/

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-present, GQL Dart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
A library for working with GraphQL documents.
2+
3+
## Usage
4+
5+
Simply use `parse`, `transform` and/or `printNode`.
6+
7+
```dart
8+
import 'package:gql/language.dart';
9+
10+
main() {
11+
final SourceFile sourceFile = SourceFile.fromString(
12+
"""
13+
type Foo {
14+
bar: Bar
15+
baz: [Baz!]!
16+
}
17+
18+
type Bar {
19+
boo: Boo
20+
}
21+
""",
22+
);
23+
24+
final DocumentNode document = parse(sourceFile);
25+
26+
final DocumentNode transformedDocument = transform(
27+
document,
28+
[
29+
MyTransformer(),
30+
MyOtherTransformer(),
31+
],
32+
);
33+
34+
final String printed = printNode(transformedDocument);
35+
36+
print(printed);
37+
}
38+
```
39+
40+
## Features and bugs
41+
42+
Please file feature requests and bugs at the [GitHub][tracker].
43+
44+
[tracker]: https://github.com/gql-dart/gql/issues

Diff for: cats/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-present, GQL Dart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: cats/analysis_options.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Defines a default set of lint rules enforced for
2+
# projects at Google. For details and rationale,
3+
# see https://github.com/dart-lang/pedantic#enabled-lints.
4+
include: package:pedantic/analysis_options.yaml
5+
6+
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
7+
# Uncomment to specify additional rules.
8+
# linter:
9+
# rules:
10+
# - camel_case_types
11+
12+
analyzer:
13+
# exclude:
14+
# - path/to/excluded/files/**

Diff for: cats/cats.iml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
7+
<excludeFolder url="file://$MODULE_DIR$/.pub" />
8+
<excludeFolder url="file://$MODULE_DIR$/build" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
<orderEntry type="library" name="Dart SDK" level="project" />
13+
<orderEntry type="library" name="Dart Packages" level="project" />
14+
</component>
15+
</module>

Diff for: cats/lib/cats.dart

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library cats;
2+
3+
export 'src/cats_base.dart';

Diff for: cats/lib/src/cat_builder.dart

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import 'dart:io';
2+
import 'dart:convert';
3+
4+
import 'package:yaml/yaml.dart';
5+
6+
import './cat_model.dart';
7+
8+
class CatBuilder {
9+
Suite buildSuite(String suitePath) {
10+
var dir = Directory(suitePath);
11+
12+
var folders = dir.listSync().whereType<Directory>();
13+
14+
var scenarios = folders.expand(
15+
(folder) => folder
16+
.listSync()
17+
.whereType<File>()
18+
.where(
19+
(file) => file.path.endsWith('.yaml'),
20+
)
21+
.map(
22+
(file) => buildScenario(file, folder),
23+
),
24+
);
25+
26+
return Suite(
27+
scenarios: scenarios,
28+
);
29+
}
30+
31+
Scenario buildScenario(File file, Directory folder) {
32+
var doc = loadYaml(
33+
file.readAsStringSync(),
34+
sourceUrl: file.path,
35+
);
36+
37+
var schema;
38+
var testData;
39+
40+
var background = doc['background'];
41+
42+
if (background != null) {
43+
schema = background['schema'];
44+
if (background['schema-file'] != null) {
45+
schema = File(
46+
'${folder.path}${Platform.pathSeparator}${background['schema-file']}',
47+
).readAsStringSync();
48+
}
49+
50+
testData = json.decode(
51+
json.encode(background['test-data']),
52+
);
53+
if (background['test-data-file'] != null) {
54+
testData = File(
55+
'${folder.path}${Platform.pathSeparator}${background['test-data-file']}',
56+
).readAsStringSync();
57+
}
58+
}
59+
60+
return Scenario(
61+
folder: folder.path,
62+
file: file.path,
63+
name: doc['scenario'],
64+
tests: buildTests(doc['tests'], folder),
65+
schema: schema,
66+
testData: testData,
67+
);
68+
}
69+
70+
Iterable<TestCase> buildTests(YamlNode node, Directory folder) {
71+
if (node is YamlList) {
72+
return node.map((n) => buildTest(n, folder));
73+
}
74+
75+
return null;
76+
}
77+
78+
TestCase buildTest(YamlMap node, Directory folder) {
79+
var background = node['given'];
80+
var query = background['query'];
81+
82+
var schema;
83+
var testData;
84+
85+
if (background != null) {
86+
schema = background['schema'];
87+
if (background['schema-file'] != null) {
88+
schema = File(
89+
'${folder.path}${Platform.pathSeparator}${background['schema-file']}',
90+
).readAsStringSync();
91+
}
92+
93+
testData = json.decode(
94+
json.encode(background['test-data']),
95+
);
96+
if (background['test-data-file'] != null) {
97+
testData = File(
98+
'${folder.path}${Platform.pathSeparator}${background['test-data-file']}',
99+
).readAsStringSync();
100+
}
101+
}
102+
103+
return TestCase(
104+
name: node['name'],
105+
query: query,
106+
schema: schema,
107+
testData: testData,
108+
action: buildAction(node['when']),
109+
assertions: buildAssertions(node['then']),
110+
);
111+
}
112+
113+
Action buildAction(YamlMap node) {
114+
if (node.containsKey('parse')) {
115+
return ParsingAction();
116+
}
117+
if (node.containsKey('validate')) {
118+
return ValidationAction(
119+
(node['validate'] as YamlList).map(
120+
(rule) => rule,
121+
),
122+
);
123+
}
124+
if (node.containsKey('execute')) {
125+
return ExecutionAction(
126+
operationName: node['operation-name'],
127+
variables: json.decode(
128+
json.encode(node['variables']),
129+
),
130+
validateQuery: node['validate-query'],
131+
testValue: node['test-value'],
132+
);
133+
}
134+
135+
return null;
136+
}
137+
138+
Iterable<Assertion> buildAssertions(YamlNode node) {
139+
if (node is YamlList) {
140+
return node.map((n) => buildAssertion(n));
141+
}
142+
143+
if (node is YamlMap) {
144+
return [buildAssertion(node)];
145+
}
146+
147+
return null;
148+
}
149+
150+
Assertion buildAssertion(YamlNode node) {
151+
if (node is YamlMap) {
152+
if (node.containsKey('passes')) {
153+
return PassesAssertion(
154+
passes: node['passes'] as bool,
155+
);
156+
}
157+
158+
if (node.containsKey('syntax-error')) {
159+
return SyntaxErrorAssertion(
160+
syntaxError: node['syntax-error'] as bool,
161+
);
162+
}
163+
164+
if (node.containsKey('error-count')) {
165+
return ErrorCountAssertion(
166+
count: node['error-count'],
167+
);
168+
}
169+
170+
if (node.containsKey('error-code')) {
171+
return ErrorCodeAssertion(
172+
errorCode: node['error-code'],
173+
// args: node['args'],
174+
// locations: node['error-code'],
175+
);
176+
}
177+
}
178+
179+
return null;
180+
}
181+
}

0 commit comments

Comments
 (0)