Skip to content

Typed options and cache helpers, scalar_mapping with imports, fetch_schema - #7

Merged
ifmelate merged 4 commits into
masterfrom
feature/v2.3-typed-options
Oct 17, 2026
Merged

ifmelate merged 4 commits into
masterfrom
feature/v2.3-typed-options

Conversation

@ifmelate

Copy link
Copy Markdown
Owner

Changes for 2.3.0. No breaking changes: everything is new API or opt-in.

Typed options for package:graphql (the Dart counterpart of TypedDocumentNode)

  • Each operation file gets <op>QueryOptions / <op>WatchQueryOptions (queries), <op>MutationOptions, <op>SubscriptionOptions. They take typed variables plus fetch and error policies, polling, optimistic results and mutation update/onCompleted/onError, and set parserFn to the generated parser, so parsedData and ObservableQuery results are typed
  • Variables parameter: required positional if any variable is required, variables: named if all are optional, absent if there are none
  • Query extensions get read<Op> (typed, null on cache miss) and write<Op> (raw data) for the normalized cache
  • Constructor parameters checked against graphql 5.1.3 sources (our lower bound); compiled and run against 5.2.1 and 5.2.4

scalar_mapping with imports

  • Long form {type, import, converter}; the short form keeps working. The import goes into types.dart and the operation files (with unused_import ignored). The converter is used for fields, list elements (json_serializable applies field converters to elements), variables and root fields
  • Mapped types without a converter use fromJson/toJson unless JSON-native
  • strict_scalars: SCH401 for custom scalars without a mapping
  • Fix: variables of a scalar mapped to DateTime were sent as raw DateTime objects

fetch_schema

  • dart run flutter_graphql_codegen:fetch_schema downloads from schema_endpoint (new key) with schema_headers into schema_url. Overrides: --config, --endpoint, --output, --header (repeatable). Exit codes: 1 = download failed, 64 = usage error
  • New dependency: args

Tests

  • 169 tests (was 144). The compile test has a new mapped variant (a converter, a fromJson/toJson type, the short form, nullable list elements), and the smoke client exercises typed query/mutate/subscribe, watchQuery typing and a cache write/read round trip
  • Also run locally on Dart 3.4.0 with the oldest resolvable dependencies: all pass

Each operation file gets functions building package:graphql options with
typed variables and the generated parser as parserFn, so
QueryResult.parsedData and ObservableQuery results are typed:
getUserQueryOptions, getUserWatchQueryOptions, renameMutationOptions,
userChangedSubscriptionOptions. Query extensions also get typed
read<Op>/write<Op> cache helpers.
- scalar_mapping entries can be `{type, import, converter}`; the import is
  added to types.dart and operation files, the converter is used on fields,
  list elements, variables and root fields
- Mapped types without a converter are read with fromJson and written with
  toJson unless they are JSON-native
- strict_scalars fails generation (SCH401) for custom scalars without a
  mapping
- Fix: variables of a scalar mapped to DateTime were sent as DateTime objects
`dart run flutter_graphql_codegen:fetch_schema` downloads the schema from
schema_endpoint (new config key) with schema_headers into schema_url, with
--config, --endpoint, --output and --header overrides.
@ifmelate
ifmelate merged commit 2035ddd into master Oct 17, 2026
2 checks passed
@ifmelate ifmelate mentioned this pull request Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant