Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codekeyz/gql_gapher
Tired of writing your GraphQL queries & mutation as raw strings `r""" """` in Dart and Flutter? 👋
https://github.com/codekeyz/gql_gapher
code-generation dart flutter graphql
Last synced: 5 days ago
JSON representation
Tired of writing your GraphQL queries & mutation as raw strings `r""" """` in Dart and Flutter? 👋
- Host: GitHub
- URL: https://github.com/codekeyz/gql_gapher
- Owner: codekeyz
- License: mit
- Created: 2022-07-14T15:51:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-10T23:08:01.000Z (about 1 year ago)
- Last Synced: 2023-11-10T23:20:09.580Z (about 1 year ago)
- Topics: code-generation, dart, flutter, graphql
- Language: Dart
- Homepage:
- Size: 47.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gql_gapher
[![Dart CI](https://github.com/codekeyz/gql_gapher/workflows/Dart/badge.svg)](https://github.com/codekeyz/gql_gapher/actions/workflows/dart.yml)
Tired of writing your queries & mutation as raw strings `r""" """` in Dart and Flutter? 👋
Validate and generate typed request classes for all your queries and mutations defined in GraphQL `(.graphql|.gql)` files. It also supports Fragments.
## Usage
Add `gql_gapher` to your dev dependencies
```yaml
dev_dependencies:
gql_gapher: any // required dart >=2.12.0
build_runner:
```### Write your queries & mutations
```graphql
mutation AuthenticateUser(
$first: String!
$second: Int!
$third: Boolean
$fourth: Float
) {
authenticate(
input: {
firebase: { token: $first }
data: { attempt: $second }
amount: $third
}
rememberMe: $fourth
) {
user {
id
phone
}
}
}
```then run the generator
```sh
# dart
dart pub run build_runner build# flutter
flutter pub run build_runner build
```### Use it
```dart
import 'authenticate.g.dart';void main() {
final authPreq = AuthenticateUserRequest('First', 2, third: true, fourth: 2.3);
print(authPreq.query); // query
print(authPreq.variables); // variables
print(authPreq.operation); // AuthenticateUser
}
```## More
### Fragments Support
Fragment Imports are supported as seen in the sample below.
```graphql
#import "../fragments/user_fragment.graphql"
#import "../fragments/location_fragment.graphql"query GetUser($token: String!) {
authenticate(input: { firebase: { token: $token } }, rememberMe: true) {
location {
name
latitude
longitude
...LocationFragment
}
...UserFragment
}
}
```## Contributors ✨
Contributions of any kind welcome!