···
830
+
it('Does not return partial data for nested selections', () => {
831
+
const client = createClient({
832
+
url: 'http://0.0.0.0',
835
+
const { source: ops$, next } = makeSubject<Operation>();
840
+
... on Todo @_optional {
852
+
const operation = client.createRequestOperation('query', {
855
+
variables: undefined,
858
+
const queryResult: OperationResult = {
862
+
__typename: 'Query',
865
+
text: 'learn urql',
866
+
__typename: 'Todo',
868
+
__typename: 'Author',
874
+
const reexecuteOperation = vi
875
+
.spyOn(client, 'reexecuteOperation')
876
+
.mockImplementation(next);
878
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
879
+
if (forwardOp.key === 1) return queryResult;
880
+
return undefined as any;
883
+
const result = vi.fn();
884
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
887
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
894
+
expect(response).toHaveBeenCalledTimes(1);
895
+
expect(result).toHaveBeenCalledTimes(1);
896
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
897
+
expect(result.mock.calls[0][0].data).toEqual(null);
900
+
it('returns partial results when an inline-fragment is marked as optional', () => {
901
+
const client = createClient({
902
+
url: 'http://0.0.0.0',
905
+
const { source: ops$, next } = makeSubject<Operation>();
912
+
... on Todo @_optional {
919
+
const operation = client.createRequestOperation('query', {
922
+
variables: undefined,
925
+
const queryResult: OperationResult = {
929
+
__typename: 'Query',
933
+
text: 'learn urql',
934
+
__typename: 'Todo',
940
+
const reexecuteOperation = vi
941
+
.spyOn(client, 'reexecuteOperation')
942
+
.mockImplementation(next);
944
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
945
+
if (forwardOp.key === 1) return queryResult;
946
+
return undefined as any;
949
+
const result = vi.fn();
950
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
953
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
960
+
expect(response).toHaveBeenCalledTimes(1);
961
+
expect(result).toHaveBeenCalledTimes(1);
962
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
963
+
expect(result.mock.calls[0][0].data).toEqual({
968
+
text: 'learn urql',
974
+
it('does not return partial results when an inline-fragment is marked as optional with a required child fragment', () => {
975
+
const client = createClient({
976
+
url: 'http://0.0.0.0',
979
+
const { source: ops$, next } = makeSubject<Operation>();
985
+
... on Todo @_optional {
987
+
... on Todo @_required {
995
+
const operation = client.createRequestOperation('query', {
998
+
variables: undefined,
1001
+
const queryResult: OperationResult = {
1005
+
__typename: 'Query',
1009
+
text: 'learn urql',
1010
+
__typename: 'Todo',
1016
+
const reexecuteOperation = vi
1017
+
.spyOn(client, 'reexecuteOperation')
1018
+
.mockImplementation(next);
1020
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
1021
+
if (forwardOp.key === 1) return queryResult;
1022
+
return undefined as any;
1025
+
const result = vi.fn();
1026
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
1029
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
1036
+
expect(response).toHaveBeenCalledTimes(1);
1037
+
expect(result).toHaveBeenCalledTimes(1);
1038
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
1039
+
expect(result.mock.calls[0][0].data).toEqual(null);
1042
+
it('does not return partial results when an inline-fragment is marked as optional with a required field', () => {
1043
+
const client = createClient({
1044
+
url: 'http://0.0.0.0',
1047
+
const { source: ops$, next } = makeSubject<Operation>();
1049
+
const query = gql`
1053
+
... on Todo @_optional {
1055
+
completed @_required
1061
+
const operation = client.createRequestOperation('query', {
1064
+
variables: undefined,
1067
+
const queryResult: OperationResult = {
1071
+
__typename: 'Query',
1075
+
text: 'learn urql',
1076
+
__typename: 'Todo',
1082
+
const reexecuteOperation = vi
1083
+
.spyOn(client, 'reexecuteOperation')
1084
+
.mockImplementation(next);
1086
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
1087
+
if (forwardOp.key === 1) return queryResult;
1088
+
return undefined as any;
1091
+
const result = vi.fn();
1092
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
1095
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
1102
+
expect(response).toHaveBeenCalledTimes(1);
1103
+
expect(result).toHaveBeenCalledTimes(1);
1104
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
1105
+
expect(result.mock.calls[0][0].data).toEqual(null);
1108
+
it('returns partial results when a fragment-definition is marked as optional', () => {
1109
+
const client = createClient({
1110
+
url: 'http://0.0.0.0',
1113
+
const { source: ops$, next } = makeSubject<Operation>();
1115
+
const query = gql`
1124
+
fragment Fields on Todo @_optional {
1129
+
const operation = client.createRequestOperation('query', {
1132
+
variables: undefined,
1135
+
const queryResult: OperationResult = {
1139
+
__typename: 'Query',
1143
+
text: 'learn urql',
1144
+
__typename: 'Todo',
1150
+
const reexecuteOperation = vi
1151
+
.spyOn(client, 'reexecuteOperation')
1152
+
.mockImplementation(next);
1154
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
1155
+
if (forwardOp.key === 1) return queryResult;
1156
+
return undefined as any;
1159
+
const result = vi.fn();
1160
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
1163
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
1170
+
expect(response).toHaveBeenCalledTimes(1);
1171
+
expect(result).toHaveBeenCalledTimes(1);
1172
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
1173
+
expect(result.mock.calls[0][0].data).toEqual(null);
it('does not return missing required fields', () => {
const client = createClient({