graphql_server2
9.0.0, released 3 weeks ago by dukefirehawk.com
Base package for executing GraphQL queries, mutations, and subscriptions against a schema.
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.
- serverpod_client
Base classes for communicating with a Serverpod backend via HTTP and WebSocket
87Compare - relic
Lightweight web server framework inspired by Shelf, with typed APIs and a high‑performance native Zig adapter.
91Compare - angel3_websocket
WebSockets support and event broadcasting for the Angel3 framework.
77Compare - dart_frog_web_socket
WebSocket support for the Dart Frog backend framework.
75Compare
Works with
Packages commonly used together with graphql_server2: ones it builds on, ones built on it, and its own family.
- stream_channelgraphql_server2 depends on itAn abstraction for two-way communication channels based on the Dart Stream class.
- recasegraphql_server2 depends on itChanges the case of input text to various conventions.
- angel3_graphqlBuilt on graphql_server2Serve GraphQL APIs over HTTP and WebSockets using the Angel3 framework.