gql_gapher 1.0.0 copy "gql_gapher: ^1.0.0" to clipboard
gql_gapher: ^1.0.0 copied to clipboard

Tired of raw strings for Graphql requests in Dart? Write fluent graphql code in your .graphql/.gql files.

gql_gapher #

Dart CI

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

dev_dependencies:
  gql_gapher: any   // required dart >=2.12.0
  build_runner:

Write your queries & mutations #

mutation AuthenticateUser(
  $first: String!
  $second: Int!
  $third: Boolean
  $fourth: Float
) {
  authenticate(
    input: {
      firebase: { token: $first }
      data: { attempt: $second }
      amount: $third
    }
    rememberMe: $fourth
  ) {
    user {
      id
      email
      phone
    }
  }
}

then run the generator

# dart
dart pub run build_runner build

# flutter
flutter pub run build_runner build

Use it #

import 'authenticate.g.dart';

void main() {
  final authPreq =
      AuthenticateUserRequest('some-token', 2, amount: 10, persist: true);

  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.

#import "../fragments/user_fragment.graphql"

mutation GetUser($token: String!) {
  authenticate(input: { firebase: { token: $token } }, rememberMe: true) {
    __typename
    ...UserFragment
  }
}

Contributors ✨ #

Contributions of any kind welcome!

1
likes
120
points
60
downloads

Publisher

unverified uploader

Weekly Downloads

Tired of raw strings for Graphql requests in Dart? Write fluent graphql code in your .graphql/.gql files.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

build, code_builder, dart_style, gql

More

Packages that depend on gql_gapher