NextJS with Apollo and Graphql use of Fragment

NextJS with Apollo and Graphql use of Fragment


0

I would like to use same basic fragments in my query.

But as soon as I use my fragment variable: ${NEXT_SEO_FRAGMENT}

I got following Error: ApolloError: Response not successful: Received status code 500

my query:

import { getApolloClient } from "../apollo-client";
import gql from 'graphql-tag'

import { Locale } from "../types";

const NEXT_SEO_FRAGMENT = gql`
  fragment NextSeoFields on NextSeoType {
    seoDescription
    seoTitle
  }
`;

export async function getHomeEntrys(locale: Locale) {
  const apolloClient = getApolloClient();

  const language = locale;
  const { data } = await apolloClient.query({
    query: gql`
      query pages($language: LanguageCodeFilterEnum!) {
        pages(where: { language: $language }) {
          edges {
            node {
              title
              content
              slug
              language {
                code
                locale
              }
              id
              isFrontPage
              nextSeo {
                ...NextSeoFields
              }
            }
          }
        }
      }
      ${NEXT_SEO_FRAGMENT}
    `,
    variables: {
        language,
      },
  });
  return data?.pages.edges
}

working code without the fragment:

import { getApolloClient } from "../apollo-client";
import gql from 'graphql-tag'

import { Locale } from "../types";

export async function getHomeEntrys(locale: Locale) {
  const apolloClient = getApolloClient();

  const language = locale;
  const { data } = await apolloClient.query({
    query: gql`
      query pages($language: LanguageCodeFilterEnum!) {
        pages(where: { language: $language }) {
          edges {
            node {
              title
              content
              slug
              language {
                code
                locale
              }
              id
              isFrontPage
              nextSeo {
                seoDescription
                seoTitle
              }
            }
          }
        }
      }
    `,
    variables: {
        language,
      },
  });
  return data?.pages.edges
}

thanks for any help, best


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *