Metadata related request returns undefined [Solved]

I’m trying to add meta data to my site.

  • I can run the query just fine in the CDA Playground
  • The frontpage generateMetadata function resolves correctly.
  • The request on a subroute returns undefiend

Frontpage query

const query = `
query Frontpage {
  site: _site {
    favicon: faviconMetaTags {
      attributes
      content
      tag
    }
  }
  frontpage {
    seo: _seoMetaTags {
      attributes
      content
      tag
    }
    blocks {
      __typename
      id
      ... on HeroRecord {
        background {
          alt
          url
        }
        title
        subtext
        callToAction {
          id
          label
          linkType
          href
          prefetch
        }
      }
    }
  }
}
`;

export async function generateMetadata() {
  const response = await performRequest<FrontendData>({ query });
  return toNextMetadata([...response.frontpage.seo, ...response.site.favicon]);
}

subroute query:

export const query = `
query SystemRefineries ($system: String!) {
  site: _site {
    favicon: faviconMetaTags {
      attributes
      content
      tag
    }
  }
  starSystem(filter: {slug: {eq: $system}}) {
    seo: _seoMetaTags {
      attributes
      content
      tag
    }
    name
    body {
      blocks {
        __typename
        ... on ImageRecord {
          id
        }
        ... on PriceTableRecord {
          id
          system
        }
        ... on RefineriesTableRecord {
          id
          system
        }
      }
    	links
      value
    }
    _status
    _firstPublishedAt
  }
}
`;

export async function generateMetadata() {
  const response = await performRequest<RefineryPageData>({ query });
  return toNextMetadata([...response.starSystem.seo, ...response.site.favicon]);
}

I have spent hours banging my head against the wall, trying to figure out why one works, but the other doesn’t.

Solved, I had forgotten to take the parameter of the subroute and feed it to the variabel param in performRequest for the generateMetadata function

1 Like