Nextjs-WPGraphQL查询菜单中的子级为null

时间:2020-11-02 08:09:36

标签: graphql next.js apollo-client wp-graphql

WPGraphiQL IDE显示正确的数据,如下所示:

enter image description here

但是当我在前端使用Apollo Client进行相同的查询时,菜单的子级将返回null。

通过查询获取数据

import { useApollo } from "../lib/apolloClient";
import { initializeApollo } from "../lib/apolloClient";
import { gql } from "@apollo/client";
function CustomApp({ pageProps, Component, props }) {
  const apolloClient = useApollo(pageProps.initialApolloState);
  return (
    <>
      {console.log(props)}
    </>
  );
}

CustomApp.getInitialProps = async () => {
  const apolloClient = initializeApollo();

  await apolloClient.query({
    query: gql`
      {
        menu(id: 2, idType: DATABASE_ID) {
          id
          databaseId
          name
          slug
          menuItems {
            nodes {
              databaseId
            }
          }
        }
      }
    `,
  });

  return {
    props: {
      initialApolloState: apolloClient.cache.extract(),
    },
  };
};

控制台:

https://i.stack.imgur.com/UdMVY.png

所有其他节点都可以毫无问题地返回子代。

0 个答案:

没有答案