Skip to content

Commit

Permalink
fix(client): make fetchMore valid with default original document again
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize committed Oct 30, 2019
1 parent e323a4d commit faa3779
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 15 additions & 3 deletions packages/graphql/lib/src/core/query_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,13 @@ class FetchMoreOptions {
DocumentNode documentNode,
this.variables = const <String, dynamic>{},
@required this.updateQuery,
}) : assert((document != null && documentNode == null) ||
(document == null && documentNode != null)),
}) : assert(
_mutuallyExclusive(document, documentNode),
'"document" or "documentNode" options are mutually exclusive.',
),
assert(updateQuery != null),
documentNode = parseString(document);
this.documentNode =
documentNode ?? document != null ? parseString(document) : null;

DocumentNode documentNode;

Expand All @@ -343,3 +346,12 @@ class FetchMoreOptions {
/// with the result data already in the cache
UpdateQuery updateQuery;
}

bool _mutuallyExclusive(
Object a,
Object b, {
bool required = false,
}) =>
(!required && a == null && b == null) ||
(a != null && b == null) ||
(a == null && b != null);
7 changes: 6 additions & 1 deletion packages/graphql/lib/src/core/raw_operation_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ class RawOperationData {
Map<String, dynamic> variables,
String operationName,
}) : assert(
document != null || documentNode != null,
'Either a "document" or "documentNode" option is required. '
'You must specify your GraphQL document in the query options.',
),
assert(
(document != null && documentNode == null) ||
(document == null && documentNode != null),
'"document" or "documentNode" option is required. You must specify your GraphQL document in the query options.',
'"document" or "documentNode" options are mutually exclusive.',
),
documentNode = documentNode ?? parseString(document),
_operationName = operationName,
Expand Down

0 comments on commit faa3779

Please sign in to comment.