Skip to content

Commit f73280c

Browse files
authored
Merge pull request #7 from hourliert/refactor/remove_mirrors
Remove mirror usage. Refactor to be code generation friendly.
2 parents 38276e0 + 6715bcb commit f73280c

Some content is hidden

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

41 files changed

+1423
-467
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.0.2
4+
5+
- Refactor the client
6+
- Create a DSL that supports very GQL features
7+
- Ready to support code generation
8+
39
## 0.0.1
410

511
- Initial version.

README.md

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,117 @@
22

33
GraphQL Client written in Dart 🎯.
44

5+
It relies on the [dart http client][http] to send GQL queries. As the **http** client, tt's platform-independent,
6+
and can be used on the command-line, browser and flutter.
7+
It has a custom DSL to write GQL queries and will have soon a code generator converting GQL queries to this DSL.
8+
Stay tuned 🎤.
9+
510
## Usage
611

7-
This is a basic PoC for now. It can't be used yet... Wait for it!
12+
For now, you have to write your GQL queries with the `graphql_client` DSL. You will be able to
13+
convert GQL queries into this DSL soon using a dart transformer.
14+
15+
The following code sample allows you to retrieve the current github user bio using the Github
16+
GraphQL API v4.
17+
18+
```dart
19+
import 'dart:async';
20+
import 'dart:io'; // Optional because I am reading env variables.
21+
22+
import 'package:http/http.dart';
23+
import 'package:logging/logging.dart'; // Optional
24+
import 'package:graphql_client/graphql_client.dart';
25+
26+
/**
27+
* Define a custom GQL query.
28+
*
29+
* The corresponding GQL is :
30+
* query ViewerBioQuery {
31+
* viewer {
32+
* bio
33+
* }
34+
* }
35+
*/
36+
37+
class ViewerBioQuery extends Object with Fields implements GQLOperation {
38+
ViewerResolver viewer = new ViewerResolver();
39+
40+
@override
41+
OperationType get type => OperationType.query;
42+
43+
@override
44+
String get name => 'ViewerBioQuery';
45+
46+
@override
47+
List<GQLField> get fields => [viewer];
48+
49+
@override
50+
ViewerBioQuery clone() => new ViewerBioQuery()..viewer = viewer.clone();
51+
}
52+
53+
class ViewerResolver extends Object with Fields implements GQLField {
54+
BioResolver bio = new BioResolver();
55+
56+
@override
57+
String get name => 'viewer';
58+
59+
@override
60+
List<GQLField> get fields => [bio];
61+
62+
@override
63+
ViewerResolver clone() => new ViewerResolver()..bio = bio.clone();
64+
}
65+
66+
class BioResolver extends Object with Scalar<String> implements GQLField {
67+
@override
68+
String get name => 'bio';
69+
70+
@override
71+
BioResolver clone() => new BioResolver();
72+
}
73+
74+
Future main() async {
75+
Logger.root
76+
..level = Level.ALL
77+
..onRecord.listen((rec) {
78+
print('${rec.level.name}: ${rec.time}: ${rec.message}');
79+
});
80+
81+
const endPoint = 'https://api.github.com/graphql';
82+
final apiToken = Platform.environment['GITHUBQL_TOKEN'];
83+
84+
final client = new Client();
85+
final logger = new Logger('GQLClient'); // This is optional.
86+
final graphQLClient = new GQLClient(
87+
client: client,
88+
logger: logger,
89+
endPoint: endPoint,
90+
);
91+
92+
final query = new ViewerBioQuery();
93+
94+
try {
95+
final queryRes = await graphQLClient.execute(
96+
query,
97+
variables: {},
98+
headers: {
99+
'Authorization': 'bearer $apiToken',
100+
},
101+
);
102+
103+
print(queryRes.viewer.bio.value); // => 'My awesome Github Bio!'
104+
} on GQLException catch (e) {
105+
print(e.message);
106+
print(e.gqlErrors);
107+
}
108+
}
109+
110+
```
111+
8112

9-
# Roadmap
113+
## Roadmap
10114

11115
You can find it [here][roadmap].
12116

13117
[roadmap]: https://github.com/hourliert/graphql_client/blob/master/ROADMAP.md
118+
[http]: https://pub.dartlang.org/packages/http

ROADMAP.md

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,19 @@
11
# High Level Roadmap
22

3-
This purpose of this library is to offer as many GraphQL features in a short amount of time.
4-
It is based on the official [spec][1]. The list of supported features are listed here.
5-
Potential but bot critic features are also listed here.
3+
This library is based on the official [spec][1]. The list of supported features are listed here.
4+
Another part of this project is to write a dart transformer that converts GQL query into dart (code generation).
65

7-
## Library components
8-
9-
Here is a basic list of library's components.
10-
11-
- `GraphQLClient`: Used to instantiate a GraphQL client using a **network transport**.
12-
This client is almost the only thing that you need to use. It posts request to a **graphql endpont** using a
13-
GQL query you built and is handling reconciliation between the HTTP response and the query type.
14-
- `QueryBuilder`: Used to transform a GQL query into a string
15-
- `QueryReconcilier`: Used to transform an HTTP response into a GQL populated query
6+
The library is fully functional today but doesn't have a code generator yet. This is in the roadmap.
167

178
## Roadmap
18-
- `QueryBuilder`:
19-
- [ ] Builder
9+
- [ ] GQL Features:
2010
- [x] Fields
2111
- [x] Arguments
22-
- [ ] Aliases
12+
- [x] Aliases
2313
- [x] Fragments
24-
- [ ] Variables
25-
- [x] Directives
26-
- [x] **Optionnal** Inline Fragments
27-
- `VariableBuilder`:
28-
- [ ] Builder
29-
- `MutationBuilder`:
30-
- [ ] Builder
31-
- [ ] Arguments
32-
- [ ] Variables
33-
- `QueryReconcilier`:
34-
- [ ] Reconciler
35-
- [ ] Reconcile Aliases
36-
- `Scalar Types`:
37-
- [ ] Implements default types
38-
- `GraphQLAnnotations` (used to define queries and mutations):
39-
- [ ] Field arguments
40-
- [ ] Field directive
41-
- [ ] Field alias
42-
- `GraphQLClient`:
43-
- [x] Factory
44-
- [ ] GraphQL Response
45-
- [ ] **Optionnal** GraphQL dart classes generation from a GQL schema
46-
- [x] **Optionnal** Translate GQL queries from String to `graphql_client` DSL
14+
- [x] Variables
15+
- [ ] Directives
16+
- [ ] Inline Fragments
17+
- [ ] Code generation: convert GQL query into dart classes
4718

4819
[1]: http://facebook.github.io/graphql/

analysis_options.yaml

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,98 @@ analyzer:
44
# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
55
linter:
66
rules:
7+
- always_declare_return_types
8+
- always_put_control_body_on_new_line
9+
- always_put_required_named_parameters_first
10+
- always_require_non_null_named_parameters
11+
- annotate_overrides
12+
- avoid_annotating_with_dynamic
13+
- avoid_as
14+
- avoid_catches_without_on_clauses
15+
- avoid_catching_errors
16+
- avoid_classes_with_only_static_members
17+
- avoid_empty_else
18+
- avoid_function_literals_in_foreach_calls
19+
- avoid_init_to_null
20+
- avoid_null_checks_in_equality_operators
21+
- avoid_positional_boolean_parameters
22+
- avoid_return_types_on_setters
23+
- avoid_returning_null
24+
- avoid_returning_this
25+
- avoid_setters_without_getters
26+
- avoid_slow_async_io
27+
- avoid_types_on_closure_parameters
28+
- await_only_futures
29+
- camel_case_types
730
- cancel_subscriptions
31+
- cascade_invocations
832
- close_sinks
33+
- comment_references
34+
- constant_identifier_names
35+
- control_flow_in_finally
36+
- directives_ordering
37+
- empty_catches
38+
- empty_constructor_bodies
39+
- empty_statements
940
- hash_and_equals
41+
- implementation_imports
42+
- invariant_booleans
1043
- iterable_contains_unrelated_type
44+
- join_return_with_assignment
45+
- library_names
46+
- library_prefixes
1147
- list_remove_unrelated_type
48+
- literal_only_boolean_expressions
49+
- no_adjacent_strings_in_list
50+
- no_duplicate_case_values
51+
- non_constant_identifier_names
52+
- omit_local_variable_types
53+
- one_member_abstracts
54+
- only_throw_errors
55+
- overridden_fields
56+
- package_api_docs
57+
- package_names
58+
- package_prefixed_library_names
59+
- parameter_assignments
60+
- prefer_adjacent_string_concatenation
61+
- prefer_asserts_in_initializer_lists
62+
- prefer_collection_literals
63+
- prefer_conditional_assignment
64+
- prefer_const_constructors
65+
- prefer_const_constructors_in_immutables
66+
- prefer_constructors_over_static_methods
67+
- prefer_contains
68+
- prefer_expression_function_bodies
69+
- prefer_final_fields
70+
- prefer_final_locals
71+
- prefer_foreach
72+
- prefer_function_declarations_over_variables
73+
- prefer_initializing_formals
74+
- prefer_interpolation_to_compose_strings
75+
- prefer_is_empty
76+
- prefer_is_not_empty
77+
- prefer_single_quotes
78+
- public_member_api_docs
79+
- recursive_getters
80+
- slash_for_doc_comments
81+
- sort_constructors_first
82+
- sort_unnamed_constructors_first
83+
- super_goes_last
1284
- test_types_in_equals
85+
- throw_in_finally
86+
- type_annotate_public_apis
87+
- type_init_formals
88+
- unawaited_futures
89+
- unnecessary_brace_in_string_interps
90+
- unnecessary_getters_setters
91+
- unnecessary_lambdas
92+
- unnecessary_null_aware_assignments
93+
- unnecessary_null_in_if_null_operators
94+
- unnecessary_overrides
95+
- unnecessary_this
1396
- unrelated_type_equality_checks
14-
- valid_regexps
97+
- use_rethrow_when_possible
98+
- use_setters_to_change_properties
99+
- use_string_buffers
100+
- use_to_and_as_if_applicable
101+
- valid_regexps

doc/code_generator.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Code Generator
2+
3+
The purpose of this document is to describe how the code generator could work.
4+
5+
## Idea
6+
7+
My idea is to be able to write your GQL queries using the GQL language.
8+
For instance write a file:
9+
10+
*MyAwesomeQuery.graphql*:
11+
```graphql
12+
query MyAwesomeQuery {
13+
viewer {
14+
login
15+
repositories(first: 5) {
16+
nodes {
17+
name
18+
}
19+
}
20+
}
21+
}
22+
```
23+
24+
Then you would run a dart transformer that reads all your graphql files and convert them
25+
into the `graphql_client` dsl and store its output files into your project.
26+
27+
You would then use the dart query format. As it follows the initial graphql query format,
28+
it would be really easy to use.
29+
30+
This is how the [Apollo Swift client][swift_client] works.
31+
32+
## Implementation
33+
34+
* Create a dart transformer
35+
* Read all `*.graphql` files
36+
* Parse the GQL using a library like [this one][graphql_parser].
37+
* Generate the corresponding dart code using the [code_builder][code_builder] library.
38+
39+
[swift_client]: http://dev.apollodata.com/ios/
40+
[graphql_parser]: https://pub.dartlang.org/packages/graphql_parser
41+
[code_builder]: https://github.com/dart-lang/code_builder

example/github_declarations.dart

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)