Skip to content

Needs to be updated for latest PWA changes #1

@lilbumblebear

Description

@lilbumblebear

I'll update as I find more, right now need to update the src/hooks/Category/useCategorySeo.js file. The only one uses the category query, which doesn't work with UID.

I fixed with this:

import { useMemo } from "react";
import { useQuery } from "@apollo/client";
import gql from "graphql-tag";

const GET_CATEGORY_SEO = gql`
  query getCategorySeo($id: String!) {
        categories(filters: { category_uid: { in: [$id] } }) {
            # eslint-disable-next-line @graphql-eslint/require-id-when-available
            items {
                uid
                mw_canonical_url {
               url
               code
            }
            meta_robots
            mw_hreflangs {
              items {
                url
                code
              }
            }
            mw_seo_markup {
                social_markup
                rich_snippets {
                  website
                  seller
                }
            }
            }
        }
  }
`;

const useProductAttachments = (props) => {
    const { id } = props;

    const { error, loading, data } = useQuery(GET_CATEGORY_SEO, {
        fetchPolicy: "cache-and-network",
        nextFetchPolicy: "cache-first",
        variables: {
            id
        }
    });

    const seoAttributes = useMemo(() => {
        if(data && data.categories.items.length){
            return data.categories.items[0];
        }
        return null;
    }, [data]);

    return {
        error,
        loading,
        seoAttributes
    };
};

export default useProductAttachments;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions