···
it('does not return missing required fields', () => {
const client = createClient({
···
+
it('Does not return partial data for nested selections', () => {
+
const client = createClient({
+
const { source: ops$, next } = makeSubject<Operation>();
+
... on Todo @_optional {
+
const operation = client.createRequestOperation('query', {
+
const queryResult: OperationResult = {
+
const reexecuteOperation = vi
+
.spyOn(client, 'reexecuteOperation')
+
.mockImplementation(next);
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
+
if (forwardOp.key === 1) return queryResult;
+
return undefined as any;
+
const result = vi.fn();
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
+
expect(response).toHaveBeenCalledTimes(1);
+
expect(result).toHaveBeenCalledTimes(1);
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
+
expect(result.mock.calls[0][0].data).toEqual(null);
+
it('returns partial results when an inline-fragment is marked as optional', () => {
+
const client = createClient({
+
const { source: ops$, next } = makeSubject<Operation>();
+
... on Todo @_optional {
+
const operation = client.createRequestOperation('query', {
+
const queryResult: OperationResult = {
+
const reexecuteOperation = vi
+
.spyOn(client, 'reexecuteOperation')
+
.mockImplementation(next);
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
+
if (forwardOp.key === 1) return queryResult;
+
return undefined as any;
+
const result = vi.fn();
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
+
expect(response).toHaveBeenCalledTimes(1);
+
expect(result).toHaveBeenCalledTimes(1);
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
+
expect(result.mock.calls[0][0].data).toEqual({
+
it('does not return partial results when an inline-fragment is marked as optional with a required child fragment', () => {
+
const client = createClient({
+
const { source: ops$, next } = makeSubject<Operation>();
+
... on Todo @_optional {
+
... on Todo @_required {
+
const operation = client.createRequestOperation('query', {
+
const queryResult: OperationResult = {
+
const reexecuteOperation = vi
+
.spyOn(client, 'reexecuteOperation')
+
.mockImplementation(next);
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
+
if (forwardOp.key === 1) return queryResult;
+
return undefined as any;
+
const result = vi.fn();
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
+
expect(response).toHaveBeenCalledTimes(1);
+
expect(result).toHaveBeenCalledTimes(1);
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
+
expect(result.mock.calls[0][0].data).toEqual(null);
+
it('does not return partial results when an inline-fragment is marked as optional with a required field', () => {
+
const client = createClient({
+
const { source: ops$, next } = makeSubject<Operation>();
+
... on Todo @_optional {
+
const operation = client.createRequestOperation('query', {
+
const queryResult: OperationResult = {
+
const reexecuteOperation = vi
+
.spyOn(client, 'reexecuteOperation')
+
.mockImplementation(next);
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
+
if (forwardOp.key === 1) return queryResult;
+
return undefined as any;
+
const result = vi.fn();
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
+
expect(response).toHaveBeenCalledTimes(1);
+
expect(result).toHaveBeenCalledTimes(1);
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
+
expect(result.mock.calls[0][0].data).toEqual(null);
+
it('returns partial results when a fragment-definition is marked as optional', () => {
+
const client = createClient({
+
const { source: ops$, next } = makeSubject<Operation>();
+
fragment Fields on Todo @_optional {
+
const operation = client.createRequestOperation('query', {
+
const queryResult: OperationResult = {
+
const reexecuteOperation = vi
+
.spyOn(client, 'reexecuteOperation')
+
.mockImplementation(next);
+
const response = vi.fn((forwardOp: Operation): OperationResult => {
+
if (forwardOp.key === 1) return queryResult;
+
return undefined as any;
+
const result = vi.fn();
+
const forward: ExchangeIO = ops$ => pipe(ops$, map(response), share);
+
cacheExchange({})({ forward, client, dispatchDebug })(ops$),
+
expect(response).toHaveBeenCalledTimes(1);
+
expect(result).toHaveBeenCalledTimes(1);
+
expect(reexecuteOperation).toHaveBeenCalledTimes(0);
+
expect(result.mock.calls[0][0].data).toEqual(null);
it('does not return missing required fields', () => {
const client = createClient({