Skip to content
pubscout

graphql_server2

9.0.0, released 3 weeks ago by dukefirehawk.com

Base package for executing GraphQL queries, mutations, and subscriptions against a schema.

WASM-ready
$ flutter pub add graphql_server2
Source repository

What it does

Executes GraphQL queries, mutations, and subscriptions against a defined schema with support for introspection. It operates without a framework or dart:mirrors, supporting AOT compilation and standard Dart execution. It also implements both graphql-transport-ws and subscriptions-transport-ws WebSocket protocols.

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

Use it when

  • You need to build a GraphQL backend or server in Dart without relying on dart:mirrors.
  • You want to handle GraphQL subscriptions over WebSockets using standard stream channels.

Skip it when

  • You need an all-in-one HTTP server integration out of the box (requires a framework adapter like angel3_graphql).
  • You want automatic reflection-based object mapping without defining resolvers or using generators.

Strengths

  • Framework-agnostic and compatible with AOT compilation.
  • Implements modern and legacy GraphQL WebSocket subscription protocols.
  • Supports full schema introspection.

Weaknesses

  • Does not include built-in HTTP handling out of the box.
  • Requires manual resolvers or a default field resolver when working with model objects instead of Maps.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5

Add `graphql_schema2` and `graphql_server2` to your pubspec.yaml.

import 'package:graphql_schema2/graphql_schema2.dart';
import 'package:graphql_server2/graphql_server2.dart';

void main() async {
  var schema = graphQLSchema(
    queryType: objectType(
      'Query',
      fields: [
        field(
          'greet',
          graphQLString,
          inputs: [GraphQLFieldInput('name', graphQLString.nonNullable())],
          resolve: (_, args) => 'Hello, ${args['name']}!',
        ),
      ],
    ),
  );
  var graphQL = GraphQL(schema);

  var data = await graphQL.parseAndExecute(
    r'query Greet($name: String!) { greet(name: $name) }',
    variableValues: {'name': 'Dart'},
  );
  print({'data': data});
}

Alternatives

Packages that do the same job and could replace graphql_server2.

Works with

Packages commonly used together with graphql_server2: ones it builds on, ones built on it, and its own family.