Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) - remove useDevtoolsContext #387

Merged
merged 5 commits into from Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/hooks/index.ts
@@ -1,4 +1,3 @@
export * from './useMutation';
export * from './useQuery';
export * from './useSubscription';
export * from './useDevtoolsContext';
117 changes: 0 additions & 117 deletions src/hooks/useDevtoolsContext.test.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/hooks/useDevtoolsContext.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/hooks/useMutation.test.tsx
Expand Up @@ -107,16 +107,6 @@ describe('on execute', () => {
);
});

it('calls executeMutation with source component info', () => {
renderer.create(<MutationUser {...props} />);
act(() => {
execute(vars);
});
expect(client.executeMutation.mock.calls[0][1]).toHaveProperty('meta', {
source: 'MutationUser',
});
});

it('can adjust context in executeMutation', () => {
renderer.create(<MutationUser {...props} />);
act(() => {
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useMutation.ts
Expand Up @@ -5,7 +5,6 @@ import { Context } from '../context';
import { OperationResult, OperationContext } from '../types';
import { CombinedError, createRequest } from '../utils';
import { useImmediateState } from './useImmediateState';
import { useDevtoolsContext } from './useDevtoolsContext';

export interface UseMutationState<T> {
fetching: boolean;
Expand All @@ -22,7 +21,6 @@ export type UseMutationResponse<T, V> = [
export const useMutation = <T = any, V = object>(
query: DocumentNode | string
): UseMutationResponse<T, V> => {
const devtoolsContext = useDevtoolsContext();
const client = useContext(Context);
const [state, setState] = useImmediateState<UseMutationState<T>>({
fetching: false,
Expand All @@ -43,15 +41,15 @@ export const useMutation = <T = any, V = object>(
const request = createRequest(query, variables as any);

return pipe(
client.executeMutation(request, { ...devtoolsContext, ...context }),
client.executeMutation(request, context || {}),
toPromise
).then(result => {
const { data, error, extensions } = result;
setState({ fetching: false, data, error, extensions });
return result;
});
},
[client, devtoolsContext, query, setState]
[client, query, setState]
);

return [state, executeMutation];
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useQuery.spec.ts
Expand Up @@ -80,7 +80,6 @@ describe('useQuery', () => {
variables: mockVariables,
},
{
meta: { source: 'TestHook' },
requestPolicy: undefined,
url: 'test',
}
Expand Down
13 changes: 0 additions & 13 deletions src/hooks/useQuery.test.tsx
Expand Up @@ -88,19 +88,6 @@ describe('on initial useEffect', () => {
})
);
});

it('passes source component name to executeQuery', () => {
renderer.create(<QueryUser {...props} />);

expect(client.executeQuery).toBeCalledWith(
expect.any(Object),
expect.objectContaining({
meta: {
source: 'QueryUser',
},
})
);
});
});

describe('on subscription', () => {
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useQuery.ts
Expand Up @@ -4,7 +4,6 @@ import { pipe, subscribe } from 'wonka';
import { Context } from '../context';
import { OperationContext, RequestPolicy } from '../types';
import { CombinedError, noop } from '../utils';
import { useDevtoolsContext } from './useDevtoolsContext';
import { useRequest } from './useRequest';
import { useImmediateEffect } from './useImmediateEffect';
import { useImmediateState } from './useImmediateState';
Expand Down Expand Up @@ -33,7 +32,6 @@ export type UseQueryResponse<T> = [
export const useQuery = <T = any, V = object>(
args: UseQueryArgs<V>
): UseQueryResponse<T> => {
const devtoolsContext = useDevtoolsContext();
const unsubscribe = useRef(noop);
const client = useContext(Context);

Expand Down Expand Up @@ -62,7 +60,6 @@ export const useQuery = <T = any, V = object>(
pollInterval: args.pollInterval,
...args.context,
...opts,
...devtoolsContext,
}),
subscribe(({ data, error, extensions }) => {
setState({ fetching: false, data, error, extensions });
Expand All @@ -74,7 +71,6 @@ export const useQuery = <T = any, V = object>(
args.requestPolicy,
args.pollInterval,
client,
devtoolsContext,
request,
setState,
]
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/useSubscription.test.tsx
Expand Up @@ -62,14 +62,6 @@ describe('on initial useEffect', () => {
expect.any(Object)
);
});

it('passes source component info to executeSubscription', () => {
renderer.create(<SubscriptionUser q={query} />);
expect(client.executeSubscription).toBeCalledWith(
expect.any(Object),
expect.objectContaining({ meta: { source: 'SubscriptionUser' } })
);
});
});

it('should support setting context in useSubscription params', () => {
Expand All @@ -85,7 +77,6 @@ it('should support setting context in useSubscription params', () => {
},
{
url: 'test',
meta: { source: 'SubscriptionUser' },
}
);
});
Expand Down
9 changes: 2 additions & 7 deletions src/hooks/useSubscription.ts
Expand Up @@ -3,7 +3,6 @@ import { useCallback, useContext, useEffect, useRef } from 'react';
import { pipe, subscribe } from 'wonka';
import { Context } from '../context';
import { CombinedError, noop } from '../utils';
import { useDevtoolsContext } from './useDevtoolsContext';
import { useRequest } from './useRequest';
import { useImmediateState } from './useImmediateState';
import { OperationContext } from '../types';
Expand All @@ -29,7 +28,6 @@ export const useSubscription = <T = any, R = T, V = object>(
args: UseSubscriptionArgs<V>,
handler?: SubscriptionHandler<T, R>
): UseSubscriptionResponse<R> => {
const devtoolsContext = useDevtoolsContext();
const unsubscribe = useRef(noop);
const client = useContext(Context);

Expand All @@ -48,10 +46,7 @@ export const useSubscription = <T = any, R = T, V = object>(
unsubscribe.current();

[unsubscribe.current] = pipe(
client.executeSubscription(request, {
...devtoolsContext,
...args.context,
}),
client.executeSubscription(request, args.context || {}),
subscribe(({ data, error, extensions }) => {
setState(s => ({
fetching: true,
Expand All @@ -61,7 +56,7 @@ export const useSubscription = <T = any, R = T, V = object>(
}));
})
);
}, [client, devtoolsContext, handler, request, setState, args.context]);
}, [client, handler, request, setState, args.context]);

// Trigger subscription on query change
// We don't use useImmediateEffect here as we have no way of
Expand Down