Skip to content

Commit 1f374f8

Browse files
authored
Merge pull request #27 from codescalers/tfchain_graphql
2 parents 249ef27 + 4b81209 commit 1f374f8

Some content is hidden

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

59 files changed

+9954
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ coverage/
77
.vscode/
88
*.iml
99
.idea
10+
/packages/*/bin/*.reflectable.dart

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos) [![codecov](https://codecov.io/gh/codescalers/tfgrid-sdk-dart/graph/badge.svg?token=O34UDTMW5O)](https://codecov.io/gh/codescalers/tfgrid-sdk-dart)
44

55
This repo contains the dart clients for Threefold grid.
6+
67
## Packages
78

89
- [signer](./packages/signer/README.md)
910
- [tfchain_client](./packages/tfchain_client/README.md)
11+
- [gridproxy_client](./packages/gridproxy_client/README.md)
12+
- [graphql_client](./packages/graphql_client/README.md)
1013
- [stellar_client](./packages/stellar_client/README.md)
14+
1115
## Prerequisites
1216

1317
Make sure you have the following tools installed:

git_hooks/pre-commit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
result=$(dart format .)
4+
exitCode=$? # If the exitCode is zero, then command executed successfully.
5+
6+
if [ $exitCode -ne 0 ]; then
7+
echo "$result"
8+
echo "Dart format found issues, please fix them."
9+
exit 1
10+
fi
11+
echo "Finished running dart format command."
12+
13+
################################################################
14+
15+
result=$(dart analyze .)
16+
exitCode=$? # If the exitCode is zero, then command executed successfully.
17+
18+
if [ $exitCode -ne 0 ]; then
19+
echo "$result"
20+
fi
21+
echo "Finished running dart analyze command."
22+
23+
################################################################
24+
25+
# Run `dart dry --apply` to auto-fix basic issues.
26+
result=$(dart fix --apply)
27+
exitCode=$?
28+
29+
# Adding the files updated by `dart fix` command to git.
30+
git add .
31+
32+
echo "$result"
33+
34+
if [ $exitCode -ne 0 ]; then
35+
echo "dart fix command failed to execute."
36+
exit 1
37+
fi
38+
echo "Finished running dart fix command."

packages/graphql_client/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Graphql Client
2+
3+
This is a dart client to send requests to graphql based on network for Threefold grid.
4+
5+
## Install Dependencies
6+
7+
``` bash
8+
dart pub get
9+
```
10+
11+
## Generate Reflectable code
12+
13+
```bash
14+
dart run build_runner build
15+
```
16+
17+
## Usage
18+
19+
- Ensure that initializeReflectable() is called at the beginning of your main
20+
21+
- Example usage:
22+
23+
```dart
24+
import 'package:graphql_client/graphql_client.dart';
25+
import 'package:graphql_client/models.dart';
26+
import 'graphql_client.reflectable.dart';
27+
28+
void main() async {
29+
initializeReflectable();
30+
31+
final graphQLClient = GraphQLClient('https://graphql.dev.grid.tf/graphql');
32+
33+
final FarmsReturnOptions farmsReturnOptions = FarmsReturnOptions(
34+
farmID: true,
35+
publicIps: PublicIpsReturnOptions(ip: true),
36+
);
37+
final FarmsQueryOptions farmsQueryOptions = FarmsQueryOptions(
38+
idEq: "farm-id",
39+
);
40+
41+
Future<List<FarmInfo>> farms = await graphQLClient.farms.list(farmsQueryOptions, farmsReturnOptions);
42+
43+
for (var farm in farms) {
44+
print(farm);
45+
}
46+
}
47+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:graphql_client/graphql_client.dart';
2+
import 'package:graphql_client/models.dart';
3+
// import 'graphql_client.reflectable.dart';
4+
5+
void main() async {
6+
// initializeReflectable();
7+
final graphQLClient = GraphQLClient('https://graphql.dev.grid.tf/graphql');
8+
9+
final res = await graphQLClient.twins.twinsConnections(
10+
TwinConnectionsReturnOptions(),
11+
TwinConnectionsQueryOptions(
12+
whereOptions: TwinQueryWhereOptions(idEq: "89")));
13+
print(res);
14+
}

packages/graphql_client/build.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
targets:
2+
$default:
3+
builders:
4+
graphql_client:
5+
generate_for:
6+
- lib/**/*.dart
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library client;
2+
3+
import 'dart:convert';
4+
5+
import 'package:graphql_client/src/contracts.dart';
6+
import 'package:graphql_client/src/farms.dart';
7+
import 'package:graphql_client/src/nodes.dart';
8+
import 'package:graphql_client/src/twins.dart';
9+
import 'package:http/http.dart' as http;
10+
11+
part 'src/client.dart';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library models;
2+
3+
import 'package:graphql_client/models/reflector.dart';
4+
import 'package:reflectable/reflectable.dart';
5+
6+
part 'models/public_ips.dart';
7+
part 'src/query_builder.dart';
8+
part 'models/twins.dart';
9+
part 'models/farms.dart';
10+
part 'models/edges.dart';
11+
part 'models/node.dart';
12+
part 'models/page_info.dart';
13+
part 'models/contracts.dart';
14+
part 'models/nodes.dart';
15+
part 'models/location.dart';
16+
part 'models/public_config.dart';
17+
part 'models/power.dart';
18+
part "models/interfaces.dart";

0 commit comments

Comments
 (0)