Skip to content

docs: update GraphQL response data docs#6997

Open
mateusz-pietras wants to merge 1 commit into
aws-amplify:mainfrom
mateusz-pietras:patch-1
Open

docs: update GraphQL response data docs#6997
mateusz-pietras wants to merge 1 commit into
aws-amplify:mainfrom
mateusz-pietras:patch-1

Conversation

@mateusz-pietras

Copy link
Copy Markdown

Clarify behavior of data field in response documentation as independent from errors field

Issue #, if available:

N/A

Description of changes:

Updates the GraphQLResponse.data dartdoc in amplify_core. The previous comment stated that data will be null whenever errors is non-empty, which does not match the GraphQL response format or Amplify's decoding behavior.

Per the GraphQL response format, data and errors are separate top-level fields. Field-level errors can be returned alongside a partial data payload (partial success). Amplify's GraphQLResponseDecoder preserves decoded data when the server returns both data and errors, for example:

// packages/api/amplify_api_dart/lib/src/graphql/helpers/graphql_response_decoder.dart
    // Found a JSON object to represent the model, parse it using model's fromJSON.
    T decodedData;

    if (modelType is PaginatedModelType) {
      final filter = request.variables['filter'] as Map<String, dynamic>?;
      final limit = request.variables['limit'] as int?;

      final resultNextToken = dataJson![_nextToken] as String?;
      dynamic requestForNextResult;
      // If result has nextToken property, prepare a request for the next page of results.
      if (resultNextToken != null) {
        final variablesWithNextToken = <String, dynamic>{
          ...request.variables,
          _nextToken: resultNextToken,
        };
        requestForNextResult = GraphQLRequest<T>(
          document: request.document,
          decodePath: request.decodePath,
          variables: variablesWithNextToken,
          modelType: request.modelType,
          authorizationMode: request.authorizationMode,
          apiName: request.apiName,
        );
      }
      decodedData =
          modelType.fromJson(
                dataJson!,
                limit: limit,
                filter: filter,
                requestForNextResult:
                    requestForNextResult
                        as GraphQLRequest<PaginatedResult<Model>>?,
              )
              as T;
    } else {
      decodedData = modelType.fromJson(dataJson!) as T;
    }
    return GraphQLResponse<T>(data: decodedData, errors: errors);

The updated documentation clarifies that data may be non-null when errors is non-empty, and directs callers to check hasErrors before treating the response as fully successful.

No runtime or API changes—documentation only.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Clarify behavior of 'data' field in response documentation as independent from `errors` field.
@mateusz-pietras mateusz-pietras requested a review from a team as a code owner May 26, 2026 21:34
@jvh-aws

jvh-aws commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Thanks a lot for the contribution

@jvh-aws jvh-aws mentioned this pull request Jun 1, 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.

2 participants