query<TParsed> method

Future<QueryResult<TParsed>> query<TParsed>(
  1. QueryOptions<TParsed> options
)

This resolves a single query according to the QueryOptions specified and returns a Future which resolves with the QueryResult or throws an Exception.

{@tool snippet} Basic usage

final QueryResult result = await client.query(
  QueryOptions(
    document: gql(
      r'''
      query ReadRepositories($nRepositories: Int!) {
        viewer {
          repositories(last: $nRepositories) {
            nodes {
              __typename
              id
              name
              viewerHasStarred
            }
          }
        }
      }
    ''',
    ),
    variables: {
      'nRepositories': 50,
    },
  ),
);

if (result.hasException) {
  print(result.exception.toString());
}

final List<dynamic> repositories =
    result.data['viewer']['repositories']['nodes'] as List<dynamic>;

{@end-tool}

Implementation

Future<QueryResult<TParsed>> query<TParsed>(
  QueryOptions<TParsed> options,
) async {
  final policies = defaultPolicies.query.withOverrides(options.policies);
  return await queryManager.query(options.copyWithPolicies(policies));
}