2022-02-21 13:32:38 +00:00
|
|
|
import { gql } from "@apollo/client";
|
2019-08-09 10:17:04 +00:00
|
|
|
import {
|
2022-03-09 08:56:55 +00:00
|
|
|
SearchAvailableProductAttributesDocument,
|
|
|
|
SearchAvailableProductAttributesQuery,
|
2022-06-21 09:36:55 +00:00
|
|
|
SearchAvailableProductAttributesQueryVariables,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/graphql";
|
|
|
|
import makeSearch from "@dashboard/hooks/makeSearch";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
2020-11-19 14:42:14 +00:00
|
|
|
export const searchProductAttributes = gql`
|
|
|
|
query SearchAvailableProductAttributes(
|
2019-08-09 10:17:04 +00:00
|
|
|
$id: ID!
|
|
|
|
$after: String
|
|
|
|
$first: Int!
|
|
|
|
$query: String!
|
|
|
|
) {
|
|
|
|
productType(id: $id) {
|
|
|
|
id
|
|
|
|
availableAttributes(
|
|
|
|
after: $after
|
|
|
|
first: $first
|
|
|
|
filter: { search: $query }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
2022-03-09 08:56:55 +00:00
|
|
|
...AvailableAttribute
|
2019-08-09 10:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
2022-03-09 08:56:55 +00:00
|
|
|
...PageInfo
|
2019-08-09 10:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-30 09:54:16 +00:00
|
|
|
export default makeSearch<
|
2022-03-09 08:56:55 +00:00
|
|
|
SearchAvailableProductAttributesQuery,
|
|
|
|
SearchAvailableProductAttributesQueryVariables
|
|
|
|
>(SearchAvailableProductAttributesDocument, result =>
|
2020-07-30 09:54:16 +00:00
|
|
|
result.loadMore(
|
|
|
|
(prev, next) => {
|
|
|
|
if (
|
|
|
|
prev.productType.availableAttributes.pageInfo.endCursor ===
|
|
|
|
next.productType.availableAttributes.pageInfo.endCursor
|
|
|
|
) {
|
|
|
|
return prev;
|
|
|
|
}
|
2019-11-20 10:24:42 +00:00
|
|
|
|
2020-07-30 09:54:16 +00:00
|
|
|
return {
|
|
|
|
...prev,
|
|
|
|
productType: {
|
|
|
|
...prev.productType,
|
|
|
|
availableAttributes: {
|
|
|
|
...prev.productType.availableAttributes,
|
|
|
|
edges: [
|
|
|
|
...prev.productType.availableAttributes.edges,
|
2022-06-21 09:36:55 +00:00
|
|
|
...next.productType.availableAttributes.edges,
|
2020-07-30 09:54:16 +00:00
|
|
|
],
|
2022-06-21 09:36:55 +00:00
|
|
|
pageInfo: next.productType.availableAttributes.pageInfo,
|
|
|
|
},
|
|
|
|
},
|
2020-07-30 09:54:16 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
{
|
2022-06-21 09:36:55 +00:00
|
|
|
after: result.data.productType.availableAttributes.pageInfo.endCursor,
|
|
|
|
},
|
|
|
|
),
|
2019-08-09 10:17:04 +00:00
|
|
|
);
|