-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
Adding 'skip' prop to query and mutation components and hooks. #229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { CombinedError, createRequest, noop } from '../utils'; | |
interface QueryHandlerProps { | ||
query: string | DocumentNode; | ||
variables?: object; | ||
skip?: boolean; | ||
client: Client; | ||
requestPolicy?: RequestPolicy; | ||
children: (arg: QueryHandlerState) => ReactNode; | ||
|
@@ -26,6 +27,8 @@ class QueryHandler extends Component<QueryHandlerProps, QueryHandlerState> { | |
private request = createRequest(this.props.query, this.props.variables); | ||
|
||
executeQuery = (opts?: Partial<OperationContext>) => { | ||
if (this.props.skip) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the props change we do call executeQuery again at which point we have to tear down the previous query. This means that unsubscribe should still be called when skip is true The update life cycle method will also have to trigger when skip changes (componentDidUpdate) |
||
|
||
this.unsubscribe(); | ||
|
||
this.setState({ fetching: true }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,9 @@ export const useMutation = <T = any, V = object>( | |
data: undefined, | ||
}); | ||
|
||
const executeMutation = (variables?: V) => { | ||
const executeMutation = (variables?: V, skip?: boolean) => { | ||
if (skip) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the component; it's imperative so the addition doesn't really make sense 😀 |
||
|
||
setState({ fetching: true, error: undefined, data: undefined }); | ||
|
||
const request = createRequest(query, variables as any); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { CombinedError, createRequest, noop } from '../utils'; | |
interface UseQueryArgs<V> { | ||
query: string | DocumentNode; | ||
variables?: V; | ||
skip?: boolean; | ||
requestPolicy?: RequestPolicy; | ||
} | ||
|
||
|
@@ -38,6 +39,8 @@ export const useQuery = <T = any, V = object>( | |
|
||
const executeQuery = useCallback( | ||
(opts?: Partial<OperationContext>) => { | ||
if (args.skip) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the component, we'll still have to call unsubscribe. It might also make sense to set fetching to false when this happens |
||
|
||
unsubscribe(); | ||
setState(s => ({ ...s, fetching: true })); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't really make sense to add skip to mutations as they're always methods that are called imperatively