Skip to content
pubscout

graphql_2_rest

2.0.0, released 2 years ago by dowhile.space

Converts GraphQL queries into REST-compatible POST bodies for any HTTP client.

WASM-ready
$ flutter pub add graphql_2_rest
Source repository

What it does

The library transforms GraphQL query strings into a format that can be sent via a standard HTTP POST request. It replaces argument and input placeholders with actual values supplied by a payload object.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to call a GraphQL endpoint using a plain HTTP client like Dio or http.
  • You want to avoid adding a full GraphQL client dependency to your project.
  • You need a lightweight solution for converting queries on the fly.

Skip it when

  • You already use a dedicated GraphQL client such as graphql_flutter or Artemis.
  • You require automatic response parsing or schema validation.

Strengths

  • No external dependencies beyond Dart SDK.
  • Works with any HTTP client, including Dio, http, or custom clients.
  • Simple API with payload classes for arguments and inputs.

Weaknesses

  • Does not handle GraphQL responses or errors automatically.
  • No schema validation or type safety for queries.
  • Limited to POST requests; does not support subscriptions or websockets.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
final dio = Dio(BaseOptions(baseUrl: 'https://endpoint/'));
final queryBuilder = GraphQLQueryBuilder(
  transformer: (q) => q.replaceAll(RegExp(r'\s+'), ' ').trim(),
);
await dio.post<dynamic>(
  'graphql/',
  data: queryBuilder.build(
    queryA,
    UserQueryPayloadA(27, 'John'),
  ),
);

Alternatives

Packages that do the same job and could replace graphql_2_rest.

  • cronet_http

    An Android Flutter plugin providing access to the Cronet HTTP client.

  • chopper

    An HTTP client generator for Dart and Flutter using source_gen.

  • http2

    An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.

  • ferry

    A GraphQL client for Dart and Flutter with code generation and normalized caching.