DPDK Architecture  ->  Library (v3.4.4)

Custom GraphQL

In some cases you might need to filter a collection through GraphQL by multiple nids, for example in a section with three cards that are all references to content.

For this specific use case we've added a custom GraphQL functionality called multipleNids.

import hydrate from '@dpdk/library/utilities/hydrate';
import gql from '@dpdk/library/utilities/gql';

function DetailPage({ contentBlocks }) {
  return <h1>contentBlock will be [{ ... }, { ... }, { ... }]</h1>;
}

Page.additionalFields = 'contentBlocks';

Page.getQuery = ({ pageData }) => {
  const nids = pageProps.contentBlocks.map(b => b.nid);
  return gql`{
    contentBlocks: content_block(filter: { nid: ${nids} }) {
      nid
      pageTitle
      call
      chat
      contentType
      linkCard
      personalStory
    }
  }`;
};

export default hydrate(Page);

Note: The field in the GraphQL call is named contentBlocks so this will override the additional field in the Page props.

Last modifiedMonday, August 30, 2021, 2:00:02 PM UTC
Last authorColin van Eenige
Commit IDfd08685