Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ graphql.config.json

# IDE
.idea

# Dart tool
.dart_tool
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# graphql_client [![Build Status](https://travis-ci.org/hourliert/graphql_client.svg?branch=master)](https://travis-ci.org/hourliert/graphql_client)
**This package and repo is no longer maintained, please follow [graphql_client](https://github.com/zino-app/graphql-flutter) instead, which is a mono repo for following packages**

UPDATE:
---
**I am not actively working on the project at the moment. I would be more than happy to receive contributions and/or grant release permission to someone else.** I like the dart ecosystem and I'd love to see a mature GraphQL library for it. I unfortunately don't have enough time to work on the project at the moment ☹️.
| Package | Pub |
| :-------------------------------------------- | :----------------------------------------------- |
| [graphql/client.dart]([./packages/graphql](https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql)) | [![version][version-badge]][package-link-client] |
| [graphql_flutter]([./packages/graphql](https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql)_flutter) | [![version][version-badge]][package-link] |

GraphQL Client written in Dart 🎯.

## Packages

This repository is the home of a set of packages for graphql_client:

### [graphql_client](graphql_client/README.md)

The GraphQL client library.

### [graphql_client_generator](graphql_client_generator/README.md)

A generator that transforms GQL query into the `graphql_client.dsl`.
[version-badge]: https://img.shields.io/pub/v/graphql_flutter.svg
[package-link]: https://pub.dartlang.org/packages/graphql_flutter
[package-link-client]: https://pub.dartlang.org/packages/graphql/versions/1.0.1
101 changes: 0 additions & 101 deletions analysis_options.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions graphql_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.0.4
- Dart 2 support

## 0.0.3

### Features
Expand Down
21 changes: 21 additions & 0 deletions graphql_client/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Thomas Hourlier, 2019 TruongSinh-Tran-Nguyen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
123 changes: 8 additions & 115 deletions graphql_client/README.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,10 @@
# graphql_client [![Build Status](https://travis-ci.org/hourliert/graphql_client.svg?branch=master)](https://travis-ci.org/hourliert/graphql_client)
**This package and repo is no longer maintained, please follow [graphql_client](https://github.com/zino-app/graphql-flutter) instead, which is a mono repo for following packages**

GraphQL Client written in Dart 🎯.
| Package | Pub |
| :-------------------------------------------- | :----------------------------------------------- |
| [graphql/client.dart]([./packages/graphql](https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql)) | [![version][version-badge]][package-link-client] |
| [graphql_flutter]([./packages/graphql](https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql)_flutter) | [![version][version-badge]][package-link] |

It relies on the [dart http client][http] to send GQL queries. As the **http** client is platform-independent,
and can be used on the command-line, browser and [Flutter](https://flutter.io).
It has a custom DSL to write GQL queries.

## Usage

For now, you have to write your GQL queries with the `graphql_client` DSL. You will be able to
convert GQL queries into this DSL soon using a dart transformer.

The following code sample allows you to retrieve the current github user bio using the Github
GraphQL API v4.

```dart
import 'dart:async';
import 'dart:io'; // Optional because I am reading env variables.

import 'package:http/http.dart';
import 'package:logging/logging.dart'; // Optional
import 'package:graphql_client/graphql_client.dart';
import 'package:graphql_client/graphql_dsl.dart';

/**
* Define a custom GQL query.
*
* The corresponding GQL is :
* query ViewerBioQuery {
* viewer {
* bio
* }
* }
*/

class ViewerBioQuery extends Object with Fields implements GQLOperation {
ViewerResolver viewer = new ViewerResolver();

@override
String get type => queryType;

@override
String get name => 'ViewerBioQuery';

@override
List<GQLField> get fields => [viewer];

@override
ViewerBioQuery clone() => new ViewerBioQuery()..viewer = viewer.clone();
}

class ViewerResolver extends Object with Fields implements GQLField {
BioResolver bio = new BioResolver();

@override
String get name => 'viewer';

@override
List<GQLField> get fields => [bio];

@override
ViewerResolver clone() => new ViewerResolver()..bio = bio.clone();
}

class BioResolver extends Object with Scalar<String> implements GQLField {
@override
String get name => 'bio';

@override
BioResolver clone() => new BioResolver();
}

Future main() async {
Logger.root // Optional
..level = Level.ALL
..onRecord.listen((rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});

const endPoint = 'https://api.github.com/graphql';
final apiToken = Platform.environment['GITHUBQL_TOKEN'];

final client = new Client();
final logger = new Logger('GQLClient'); // Optional.
final graphQLClient = new GQLClient(
client: client,
logger: logger,
endPoint: endPoint,
);

final query = new ViewerBioQuery();

try {
final queryRes = await graphQLClient.execute(
query,
variables: {},
headers: {
'Authorization': 'bearer $apiToken',
},
);

print(queryRes.viewer.bio.value); // => 'My awesome Github Bio!'
} on GQLException catch (e) {
print(e.message);
print(e.gqlErrors);
}
}

```

## Roadmap

You can find it [here](ROADMAP.md).

[roadmap]: (ROADMAP.md)
[http]: https://pub.dartlang.org/packages/http
[version-badge]: https://img.shields.io/pub/v/graphql_flutter.svg
[package-link]: https://pub.dartlang.org/packages/graphql_flutter
[package-link-client]: https://pub.dartlang.org/packages/graphql/versions/1.0.1
1 change: 1 addition & 0 deletions graphql_client/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:perfectionist/analysis_options.yaml
25 changes: 13 additions & 12 deletions graphql_client/example/graphql_client_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ Future main() async {
const endPoint = 'https://api.github.com/graphql';
final apiToken = Platform.environment['GQL_GITHUB_TOKEN'];

final client = new Client();
final logger = new Logger('GQLClient');
final graphQLClient = new GQLClient(
final client = Client();
final logger = Logger('GQLClient');
final graphQLClient = GQLClient(
client: client,
logger: logger,
endPoint: endPoint,
);

final query = new LoginQuery();
final mutation = new AddTestCommentMutation();
final query = LoginQuery();
final mutation = AddTestCommentMutation();

try {
print('\n\n===================== TEST 1 =====================');

final queryRes = await graphQLClient.execute(
query,
variables: {'issueId': 'MDU6SXNzdWUyNDQzNjk1NTI', 'body': 'Test issue 2'},
headers: {
variables: <String, String>{'issueId': 'MDU6SXNzdWUyNDQzNjk1NTI', 'body': 'Test issue 2'},
headers: <String, String>{
'Authorization': 'bearer $apiToken',
},
);
Expand All @@ -61,7 +61,8 @@ Future main() async {
print(queryRes.viewer.gist.description.value);

print('=== .repositories ===');
for (var n in queryRes.viewer.repositories.nodes) {
// @todo better if we don't have to cast here
for (var n in queryRes.viewer.repositories.nodes.cast<NodesResolver>()) {
print(n.repoName.value);
}
} on GQLException catch (e) {
Expand All @@ -76,8 +77,8 @@ Future main() async {

final mutationRes = await graphQLClient.execute(
mutation,
variables: {'issueId': 'MDU6SXNzdWUyNDQzNjk1NTI', 'body': 'Test issue '},
headers: {
variables: <String, String>{'issueId': 'MDU6SXNzdWUyNDQzNjk1NTI', 'body': 'Test issue '},
headers: <String, String>{
'Authorization': 'bearer $apiToken',
},
);
Expand All @@ -96,8 +97,8 @@ Future main() async {

await graphQLClient.execute(
mutation,
variables: {'issueId': 'efwef', 'body': 'Test issue'},
headers: {
variables: <String, String>{'issueId': 'efwef', 'body': 'Test issue'},
headers: <String, String>{
'Authorization': 'bearer $apiToken',
},
);
Expand Down
Loading