2022-02-21 13:32:38 +00:00
|
|
|
import { gql } from "@apollo/client";
|
2020-11-19 14:42:14 +00:00
|
|
|
import {
|
2022-03-09 08:56:55 +00:00
|
|
|
SearchAvailablePageAttributesDocument,
|
|
|
|
SearchAvailablePageAttributesQuery,
|
2022-06-21 09:36:55 +00:00
|
|
|
SearchAvailablePageAttributesQueryVariables,
|
2022-03-09 08:56:55 +00:00
|
|
|
} from "@saleor/graphql";
|
|
|
|
import makeSearch from "@saleor/hooks/makeSearch";
|
2020-11-19 14:42:14 +00:00
|
|
|
|
|
|
|
export const searchPageAttributes = gql`
|
|
|
|
query SearchAvailablePageAttributes(
|
|
|
|
$id: ID!
|
|
|
|
$after: String
|
|
|
|
$first: Int!
|
|
|
|
$query: String!
|
|
|
|
) {
|
|
|
|
pageType(id: $id) {
|
|
|
|
id
|
|
|
|
availableAttributes(
|
|
|
|
after: $after
|
|
|
|
first: $first
|
|
|
|
filter: { search: $query }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
2022-03-09 08:56:55 +00:00
|
|
|
...AvailableAttribute
|
2020-11-19 14:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
2022-03-09 08:56:55 +00:00
|
|
|
...PageInfo
|
2020-11-19 14:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default makeSearch<
|
2022-03-09 08:56:55 +00:00
|
|
|
SearchAvailablePageAttributesQuery,
|
|
|
|
SearchAvailablePageAttributesQueryVariables
|
|
|
|
>(SearchAvailablePageAttributesDocument, result =>
|
2020-11-19 14:42:14 +00:00
|
|
|
result.loadMore(
|
|
|
|
(prev, next) => {
|
|
|
|
if (
|
|
|
|
prev.pageType.availableAttributes.pageInfo.endCursor ===
|
|
|
|
next.pageType.availableAttributes.pageInfo.endCursor
|
|
|
|
) {
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prev,
|
|
|
|
pageType: {
|
|
|
|
...prev.pageType,
|
|
|
|
availableAttributes: {
|
|
|
|
...prev.pageType.availableAttributes,
|
|
|
|
edges: [
|
|
|
|
...prev.pageType.availableAttributes.edges,
|
2022-06-21 09:36:55 +00:00
|
|
|
...next.pageType.availableAttributes.edges,
|
2020-11-19 14:42:14 +00:00
|
|
|
],
|
2022-06-21 09:36:55 +00:00
|
|
|
pageInfo: next.pageType.availableAttributes.pageInfo,
|
|
|
|
},
|
|
|
|
},
|
2020-11-19 14:42:14 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
{
|
2022-06-21 09:36:55 +00:00
|
|
|
after: result.data.pageType.availableAttributes.pageInfo.endCursor,
|
|
|
|
},
|
|
|
|
),
|
2020-11-19 14:42:14 +00:00
|
|
|
);
|