Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vezaynk committed Feb 1, 2024
2 parents eb846a4 + 4faeb5c commit 1684e9c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @apollo/client

## 3.9.2

### Patch Changes

- [#11552](https://github.com/apollographql/apollo-client/pull/11552) [`6ac2b0c`](https://github.com/apollographql/apollo-client/commit/6ac2b0ce4d999c63478d85b40ad56ccda9624797) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix import in `useLazyRef` causing import issues in the nextjs package.

## 3.9.1

### Patch Changes
Expand Down
1 change: 0 additions & 1 deletion docs/shared/ApiDoc/EnumDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function EnumDetails({
mr="1"
as={Text}
since
link
id={`${item.displayName.toLowerCase()}-member-${member.displayName.toLowerCase()}`}
/>
<DocBlock
Expand Down
28 changes: 16 additions & 12 deletions docs/shared/ApiDoc/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
PropertySignatureTable,
SourceLink,
Example,
getInterfaceReference,
} from ".";
import { GridItem } from "@chakra-ui/react";
export function FunctionSignature({
Expand All @@ -22,7 +21,8 @@ export function FunctionSignature({
}) {
const MDX = useMDXComponents();
const getItem = useApiDocContext();
const { displayName, parameters, returnType } = getItem(canonicalReference);
const { displayName, parameters, returnType, typeParameters } =
getItem(canonicalReference);

let paramSignature = parameters
.map((p) => {
Expand All @@ -41,9 +41,16 @@ export function FunctionSignature({
paramSignature = "\n " + paramSignature + "\n";
}

const genericSignature =
typeParameters?.length ?
`<${typeParameters.map((p) => p.name).join(", ")}>`
: "";

const signature = `${arrow ? "" : "function "}${
name ? displayName : ""
}(${paramSignature})${arrow ? " =>" : ":"} ${returnType}`;
}${genericSignature}(${paramSignature})${arrow ? " =>" : ":"} ${
returnType.type
}`;

return highlight ?
<MDX.pre language="ts">
Expand All @@ -65,24 +72,20 @@ export function ReturnType({ canonicalReference }) {
const getItem = useApiDocContext();
const item = getItem(canonicalReference);

const interfaceReference = getInterfaceReference(
item.returnType,
item,
getItem
);
return (
<>
{item.comment?.returns}
<MDX.pre language="ts">
<code className="language-ts">{item.returnType}</code>
<code className="language-ts">{item.returnType.type}</code>
</MDX.pre>
{interfaceReference ?
{item.returnType.primaryCanonicalReference?.endsWith(":interface") ?
<details>
<GridItem as="summary" className="row">
Show/hide child attributes
</GridItem>
<PropertySignatureTable
canonicalReference={interfaceReference.canonicalReference}
canonicalReference={item.returnType.primaryCanonicalReference}
genericNames={item.returnType.primaryGenericArguments}
idPrefix={`${item.displayName.toLowerCase()}-result`}
/>
</details>
Expand Down Expand Up @@ -153,7 +156,8 @@ export function FunctionDetails({
</>
)}
{(
result === false || (result === undefined && item.returnType === "void")
result === false ||
(result === undefined && item.returnType.type === "void")
) ?
null
: <>
Expand Down
19 changes: 7 additions & 12 deletions docs/shared/ApiDoc/ParameterTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { useMDXComponents } from "@mdx-js/react";
import PropTypes from "prop-types";
import React from "react";
import { GridItem, Text } from "@chakra-ui/react";
import {
PropertySignatureTable,
SectionHeading,
getInterfaceReference,
useApiDocContext,
} from ".";
import { PropertySignatureTable, useApiDocContext } from ".";
import { ResponsiveGrid } from "./ResponsiveGrid";

export function ParameterTable({ canonicalReference }) {
Expand All @@ -25,11 +20,10 @@ export function ParameterTable({ canonicalReference }) {
<GridItem className="cell heading">Description</GridItem>

{item.parameters.map((parameter) => {
const interfaceReference = getInterfaceReference(
parameter.type,
item,
getItem
);
const interfaceReference =
parameter.primaryCanonicalReference?.endsWith(":interface") ?
parameter.primaryCanonicalReference
: undefined;
const id = `${item.displayName.toLowerCase()}-parameters-${parameter.name.toLowerCase()}`;

return (
Expand Down Expand Up @@ -68,7 +62,8 @@ export function ParameterTable({ canonicalReference }) {
Show/hide child attributes
</GridItem>
<PropertySignatureTable
canonicalReference={interfaceReference.canonicalReference}
canonicalReference={interfaceReference}
genericNames={parameter.primaryGenericArguments}
display="child"
idPrefix={id}
/>
Expand Down
31 changes: 27 additions & 4 deletions docs/shared/ApiDoc/PropertySignatureTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function PropertySignatureTable({
display = "parent",
customOrder = [],
idPrefix = "",
genericNames,
}) {
const MDX = useMDXComponents();
const getItem = useApiDocContext();
Expand All @@ -36,6 +37,28 @@ export function PropertySignatureTable({
);
}

const replaceGenericNames = React.useMemo(() => {
if (!genericNames) return (str) => str;

const replacements = {};
item.typeParameters.forEach((p, i) => {
if (genericNames[i] === p.name) return;
replacements[p.name] = genericNames[i];
});
if (!Object.values(replacements).length) return (str) => str;

const genericReplacementRegex = new RegExp(
`\\b(${Object.keys(replacements).join("|")})\\b`,
"g"
);
function replace(match) {
return replacements[match] || match;
}
return function replaceGenericNames(str) {
return str.replace(genericReplacementRegex, replace);
};
});

return (
<>
{item.childrenIncomplete ?
Expand All @@ -55,7 +78,7 @@ export function PropertySignatureTable({
: null}
{Object.entries(groupedProperties).map(
([groupName, sortedProperties]) => (
<>
<React.Fragment key={groupName}>
{groupName ?
<GridItem className="row heading">{groupName}</GridItem>
: null}
Expand All @@ -79,7 +102,6 @@ export function PropertySignatureTable({
: null
}
suffix={property.optional ? <em> (optional)</em> : null}
link={!!idPrefix}
id={
idPrefix ?
`${idPrefix}-${property.displayName.toLowerCase()}`
Expand All @@ -94,7 +116,7 @@ export function PropertySignatureTable({
parameterTypes
arrow
/>
: property.type}
: replaceGenericNames(property.type)}
</MDX.inlineCode>
</GridItem>
<GridItem className="cell" fontSize="md" lineHeight="base">
Expand All @@ -109,7 +131,7 @@ export function PropertySignatureTable({
</GridItem>
</React.Fragment>
))}
</>
</React.Fragment>
)
)}
</Wrapper>
Expand All @@ -124,4 +146,5 @@ PropertySignatureTable.propTypes = {
display: PropTypes.oneOf(["parent", "child"]),
customOrder: PropTypes.arrayOf(PropTypes.string),
idPrefix: PropTypes.string,
genericNames: PropTypes.arrayOf(PropTypes.string),
};
8 changes: 0 additions & 8 deletions docs/shared/ApiDoc/getInterfaceReference.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/shared/ApiDoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ export { ParameterTable } from "./ParameterTable";
export { PropertyDetails } from "./PropertyDetails";
export { EnumDetails } from "./EnumDetails";
export { ManualTuple } from "./Tuple";
export { getInterfaceReference } from "./getInterfaceReference";
export { SourceLink } from "./SourceLink";
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apollo/client",
"version": "3.9.1",
"version": "3.9.2",
"description": "A fully-featured caching GraphQL client.",
"private": true,
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/internal/useLazyRef.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react";
import * as React from "rehackt";

const INIT = {};

Expand Down

0 comments on commit 1684e9c

Please sign in to comment.