gql_link 1.0.1-alpha+1709670733561 copy "gql_link: ^1.0.1-alpha+1709670733561" to clipboard
gql_link: ^1.0.1-alpha+1709670733561 copied to clipboard

A simple and modular AST-based GraphQL request execution interface.

example/gql_link_example.dart

import "package:gql/language.dart";
import "package:gql_exec/gql_exec.dart";
import "package:gql_link/gql_link.dart";

class MyLinkContext extends ContextEntry {
  final int value;

  const MyLinkContext(this.value);

  @override
  List<Object> get fieldsForEquality => [];
}

class MyLink extends Link {
  @override
  Stream<Response> request(Request request, [forward]) => Stream.fromIterable(
        [
          Response(
            data: <String, dynamic>{
              "context": request.context.entry<MyLinkContext>()?.value,
            },
            response: <String, dynamic>{
              "data": <String, dynamic>{
                "context": request.context.entry<MyLinkContext>()?.value,
              }
            },
          ),
        ],
      );
}

void main() async {
  final link = MyLink();

  for (var i = 0; i < 10; i++) {
    final first = await link
        .request(
          Request(
            operation: Operation(
              document: parseString(""),
            ),
            context: Context.fromMap(
              <Type, ContextEntry>{
                MyLinkContext: MyLinkContext(i),
              },
            ),
          ),
        )
        .first;

    print(first.data);
  }
}
20
likes
0
pub points
91%
popularity

Publisher

verified publishergql-dart.dev

A simple and modular AST-based GraphQL request execution interface.

Repository (GitHub)
View/report issues

Topics

#graphql #gql #gql-link

License

unknown (license)

Dependencies

gql, gql_exec, meta

More

Packages that depend on gql_link