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

Document new React APIs in code - Part 2 of 2 #11523

Merged
merged 28 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b65afd
Mark symbols in QueryReference as internal
jerelmiller Jan 25, 2024
8f22e23
Add documentation on toPromise for QueryReference
jerelmiller Jan 25, 2024
b479711
Add inline code tag in createQueryPreloader description
jerelmiller Jan 25, 2024
2be5751
Add since tag to createQueryPreloader
jerelmiller Jan 25, 2024
00e075c
Add docblock for useLoadableQuery
jerelmiller Jan 25, 2024
7efaa70
Add useLoadableQuery to hooks page
jerelmiller Jan 25, 2024
44c7514
Add `@since` tag to useQueryRefHandlers
jerelmiller Jan 25, 2024
8623b09
Add useQueryRefHandlers to hooks documentation
jerelmiller Jan 25, 2024
40e10dc
Add link to documentation on createQueryPreloader
jerelmiller Jan 25, 2024
811c1dd
Rerun extract api report
jerelmiller Jan 25, 2024
fd229f6
Add additional info for toPromise
jerelmiller Jan 25, 2024
1d15fd3
Move doc for useLoadableQuery to first overload
jerelmiller Jan 26, 2024
7414629
Create a type for the handlers returned from useLoadableQuery
jerelmiller Jan 26, 2024
e9f56d6
Add doc comments to useLoadableQuery handlers
jerelmiller Jan 26, 2024
3e59cbe
Add more detailed code for useLoadableQuery
jerelmiller Jan 26, 2024
d6fcb1b
List createQueryPreloader as alpha
jerelmiller Jan 26, 2024
3199bb7
Clean up Prettier, Size-limit, and Api-Extractor
jerelmiller Jan 26, 2024
a80245e
Use `@alpha` designation for toPromise on QueryReference
jerelmiller Jan 26, 2024
44cc612
Clean up Prettier, Size-limit, and Api-Extractor
jerelmiller Jan 26, 2024
b88f14e
Fix id prefix
jerelmiller Jan 26, 2024
841f88d
Fix syntax error in list
jerelmiller Jan 26, 2024
3c572b1
Add new preloading doc for createQueryPreloader
jerelmiller Jan 26, 2024
b0516e2
Revert change to add handlers type
jerelmiller Jan 26, 2024
4760636
Allow overrides to be formatted
jerelmiller Jan 26, 2024
9b14c23
Move result override for useLoadableQuery to own component
jerelmiller Jan 26, 2024
0cef515
Move description for useLoadableQuery to last overload
jerelmiller Jan 26, 2024
b6a7040
Extract API
jerelmiller Jan 26, 2024
66b958e
Ensure | null is added to queryRef in return type
jerelmiller Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .api-reports/api-report-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
export interface Context extends Record<string, any> {
}

// @public
// @alpha
export function createQueryPreloader(client: ApolloClient<any>): PreloadQueryFunction;

// @public (undocumented)
Expand Down Expand Up @@ -1759,13 +1759,13 @@ interface QueryOptions<TVariables = OperationVariables, TData = any> {
//
// @public
export interface QueryReference<TData = unknown, TVariables = unknown> {
// (undocumented)
// @internal (undocumented)
[PROMISE_SYMBOL]: QueryRefPromise<TData>;
// Warning: (ae-forgotten-export) The symbol "InternalQueryReference" needs to be exported by the entry point index.d.ts
//
// (undocumented)
// @internal (undocumented)
readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;
// (undocumented)
// @alpha
toPromise(): Promise<QueryReference<TData, TVariables>>;
}

Expand Down Expand Up @@ -2251,13 +2251,13 @@ export function useLoadableQuery<TData = unknown, TVariables extends OperationVa
returnPartialData: true;
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

// @public (undocumented)
// @public
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;

// @public (undocumented)
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
LoadQueryFunction<TVariables>,
QueryReference<TData, TVariables> | null,
loadQuery: LoadQueryFunction<TVariables>,
queryRef: QueryReference<TData, TVariables> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
Expand Down Expand Up @@ -2398,7 +2398,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/watchQueryOptions.ts:269:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:106:1 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
14 changes: 7 additions & 7 deletions .api-reports/api-report-react_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1634,13 +1634,13 @@ interface QueryOptions<TVariables = OperationVariables, TData = any> {
//
// @public
interface QueryReference<TData = unknown, TVariables = unknown> {
// (undocumented)
// @internal (undocumented)
[PROMISE_SYMBOL]: QueryRefPromise<TData>;
// Warning: (ae-forgotten-export) The symbol "InternalQueryReference" needs to be exported by the entry point index.d.ts
//
// (undocumented)
// @internal (undocumented)
readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;
// (undocumented)
// @alpha
toPromise(): Promise<QueryReference<TData, TVariables>>;
}

Expand Down Expand Up @@ -2091,13 +2091,13 @@ export function useLoadableQuery<TData = unknown, TVariables extends OperationVa
returnPartialData: true;
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

// @public (undocumented)
// @public
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;

// @public (undocumented)
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
LoadQueryFunction<TVariables>,
QueryReference<TData, TVariables> | null,
loadQuery: LoadQueryFunction<TVariables>,
queryRef: QueryReference<TData, TVariables> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
Expand Down Expand Up @@ -2234,7 +2234,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/watchQueryOptions.ts:269:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:106:1 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
6 changes: 3 additions & 3 deletions .api-reports/api-report-react_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -1398,11 +1398,11 @@ interface QueryOptions<TVariables = OperationVariables, TData = any> {
//
// @public
export interface QueryReference<TData = unknown, TVariables = unknown> {
// (undocumented)
// @internal (undocumented)
[PROMISE_SYMBOL]: QueryRefPromise<TData>;
// (undocumented)
// @internal (undocumented)
readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;
// (undocumented)
// @alpha
toPromise(): Promise<QueryReference<TData, TVariables>>;
}

Expand Down
16 changes: 8 additions & 8 deletions .api-reports/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ export const concat: typeof ApolloLink.concat;
// @public (undocumented)
export const createHttpLink: (linkOptions?: HttpOptions) => ApolloLink;

// @public
// @alpha
export function createQueryPreloader(client: ApolloClient<any>): PreloadQueryFunction;

// @public @deprecated (undocumented)
Expand Down Expand Up @@ -2323,13 +2323,13 @@ export { QueryOptions }
//
// @public
export interface QueryReference<TData = unknown, TVariables = unknown> {
// (undocumented)
// @internal (undocumented)
[PROMISE_SYMBOL]: QueryRefPromise<TData>;
// Warning: (ae-forgotten-export) The symbol "InternalQueryReference" needs to be exported by the entry point index.d.ts
//
// (undocumented)
// @internal (undocumented)
readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;
// (undocumented)
// @alpha
toPromise(): Promise<QueryReference<TData, TVariables>>;
}

Expand Down Expand Up @@ -2904,13 +2904,13 @@ export function useLoadableQuery<TData = unknown, TVariables extends OperationVa
returnPartialData: true;
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

// @public (undocumented)
// @public
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;

// @public (undocumented)
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
LoadQueryFunction<TVariables>,
QueryReference<TData, TVariables> | null,
loadQuery: LoadQueryFunction<TVariables>,
queryRef: QueryReference<TData, TVariables> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
Expand Down Expand Up @@ -3077,7 +3077,7 @@ interface WriteContext extends ReadMergeModifyContext {
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:106:1 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/docs/shared/**
!/docs/shared/ApiDoc
!/docs/shared/ApiDoc/**
!/docs/shared/Overrides
!/docs/shared/Overrides/**

node_modules/
.yalc/
Expand Down
58 changes: 58 additions & 0 deletions docs/shared/Overrides/UseLoadableQueryResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from "react";
import { useMDXComponents } from "@mdx-js/react";
import { ManualTuple } from "../ApiDoc";

const HANDLERS = `{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
reset: ResetFunction;
}`;

const RETURN_VALUE = `[
loadQuery: LoadQueryFunction<TVariables>,
queryRef: QueryReference<TData, TVariables> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
reset: ResetFunction;
}
]`;

export function UseLoadableQueryResult() {
const MDX = useMDXComponents();

return (
<div>
<MDX.pre>
<code className="language-ts">{RETURN_VALUE}</code>
</MDX.pre>
A tuple of three values:
<ManualTuple
idPrefix="useloadablequery-result"
elements={[
{
name: "loadQuery",
type: "LoadQueryFunction<TVariables>",
description:
"A function used to imperatively load a query. Calling this function will create or update the `queryRef` returned by `useLoadableQuery`, which should be passed to `useReadQuery`.",
},
{
name: "queryRef",
type: "QueryReference<TData, TVariables> | null",
description:
"The `queryRef` used by `useReadQuery` to read the query result.",
canonicalReference: "@apollo/client!QueryReference:interface",
},
{
name: "handlers",
description:
"Additional handlers used for the query, such as `refetch`.",
type: HANDLERS,
},
]}
/>
</div>
);
}

UseLoadableQueryResult.propTypes = {};
11 changes: 11 additions & 0 deletions docs/source/api/react/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ api_doc:
- "@apollo/client!useSubscription:function(1)"
- "@apollo/client!useApolloClient:function(1)"
- "@apollo/client!useReactiveVar:function(1)"
- "@apollo/client!useLoadableQuery:function(5)"
- "@apollo/client!useQueryRefHandlers:function(1)"
---

import UseFragmentOptions from '../../../shared/useFragment-options.mdx';
Expand All @@ -19,6 +21,7 @@ import UseSuspenseQueryResult from '../../../shared/useSuspenseQuery-result.mdx'
import UseBackgroundQueryResult from '../../../shared/useBackgroundQuery-result.mdx';
import UseReadQueryResult from '../../../shared/useReadQuery-result.mdx';
import { FunctionDetails, PropertySignatureTable, ManualTuple, InterfaceDetails } from '../../../shared/ApiDoc';
import { UseLoadableQueryResult } from '../../../shared/Overrides/UseLoadableQueryResult'

## The `ApolloProvider` component

Expand Down Expand Up @@ -405,6 +408,14 @@ function useReadQuery<TData>(

<UseReadQueryResult />

<FunctionDetails
canonicalReference="@apollo/client!useLoadableQuery:function(5)"
headingLevel={2}
result={<UseLoadableQueryResult />}
/>

<FunctionDetails canonicalReference="@apollo/client!useQueryRefHandlers:function(1)" headingLevel={2} />

<MinVersion version="3.8.0">

## `skipToken`
Expand Down
11 changes: 11 additions & 0 deletions docs/source/api/react/preloading.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Preloading
description: Apollo Client preloading API reference
minVersion: 3.9.0
api_doc:
- "@apollo/client!createQueryPreloader:function(1)"
---

import { FunctionDetails } from '../../../shared/ApiDoc';

<FunctionDetails canonicalReference="@apollo/client!createQueryPreloader:function(1)" headingLevel={2} />
1 change: 1 addition & 0 deletions docs/source/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
},
"React": {
"Hooks": "/api/react/hooks",
"Preloading": "/api/react/preloading",
"Testing": "/api/react/testing",
"SSR": "/api/react/ssr",
"Components (deprecated)": "/api/react/components",
Expand Down
54 changes: 52 additions & 2 deletions src/react/hooks/useLoadableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ export type UseLoadableQueryResult<
TData = unknown,
TVariables extends OperationVariables = OperationVariables,
> = [
LoadQueryFunction<TVariables>,
QueryReference<TData, TVariables> | null,
loadQuery: LoadQueryFunction<TVariables>,
queryRef: QueryReference<TData, TVariables> | null,
{
/** {@inheritDoc @apollo/client!QueryResultDocumentation#fetchMore:member} */
fetchMore: FetchMoreFunction<TData, TVariables>;
/** {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member} */
refetch: RefetchFunction<TData, TVariables>;
/**
* A function that resets the `queryRef` back to `null`.
*/
reset: ResetFunction;
},
];
Expand Down Expand Up @@ -98,6 +103,51 @@ export function useLoadableQuery<
}
): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

/**
* A hook for imperatively loading a query, such as responding to a user
* interaction.
*
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
*
* @example
* ```jsx
* import { gql, useLoadableQuery } from "@apollo/client";
*
* const GET_GREETING = gql`
* query GetGreeting($language: String!) {
* greeting(language: $language) {
* message
* }
* }
* `;
*
* function App() {
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
*
* return (
* <>
* <button onClick={() => loadGreeting({ language: "english" })}>
* Load greeting
* </button>
* <Suspense fallback={<div>Loading...</div>}>
* {queryRef && <Hello queryRef={queryRef} />}
* </Suspense>
* </>
* );
* }
*
* function Hello({ queryRef }) {
* const { data } = useReadQuery(queryRef);
*
* return <div>{data.greeting.message}</div>;
* }
* ```
*
* @since 3.9.0
* @param query - A GraphQL query document parsed into an AST by `gql`.
* @param options - Options to control how the query is executed.
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
*/
export function useLoadableQuery<
TData = unknown,
TVariables extends OperationVariables = OperationVariables,
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/useQueryRefHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface UseQueryRefHandlersResult<
* // ...
* }
* ```
*
* @since 3.9.0
* @param queryRef - A `QueryReference` returned from `useBackgroundQuery`, `useLoadableQuery`, or `createQueryPreloader`.
*/
export function useQueryRefHandlers<
Expand Down
Loading
Loading