Contentful logo

Contentful Community

GraphQL Fragment for RichText

Hey all,

I am receiving this error when executing my query. I have reduced my query as much as possible, but it’s still large.
My full query looks like this:

query getPage($id: String!) {
  page(id: $id) {
    title
    breadcrumbEnabled
    header {
      __typename
      ...SectionAbout
      ...SectionBrandHero
      ...BrandSection
      ...SectionCallToAction
      ...SectionFindUs
      ...SectionGallery
      ...SectionImageColumn
      ...SectionLive
      ...SectionMultipleRows
      ...SectionPartners
      ...SectionProducts
      ...SectionTheatres
    }
    contentCollection(limit: 8) {
      items {
        __typename
        ...SectionAbout
        ...SectionBrandHero
        ...BrandSection
        ...SectionCallToAction
        ...SectionFindUs
        ...SectionGallery
        ...SectionImageColumn
        ...SectionLive
        ...SectionMultipleRows
        ...SectionPartners
        ...SectionProducts
        ...SectionTheatres
      }
      __typename
    }
    __typename
  }
}

fragment SectionAbout on SectionAbout {
  title
  hero {
    ...GalleryHero
    __typename
  }
  itemsCollection(limit: 2) {
    items {
      ...GalleryItem
      __typename
    }
    __typename
  }
  __typename
}

fragment GalleryItem on GalleryItem {
  title
  color
  description {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  link
  imagePanel: image {
    title
    image
    link
    __typename
  }
  __typename
}

fragment GalleryHero on GalleryHero {
  __typename
  title
  imagePanelsCollection {
    items {
      ...ImagePanel
      __typename
    }
    __typename
  }
}

fragment ImagePanel on ImagePanel {
  title
  descriptionText: description
  button {
    ...ButtonLink
    __typename
  }
  color
  image
  link
  __typename
}

fragment ButtonLink on ButtonLink {
  __typename
  name
  href
  color
  elevation
}

fragment SectionBrandHero on SectionBrandHero {
  __typename
  title
  backgroundImage
  content {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  buttonsCollection(limit: 3) {
    items {
      ...ButtonLink
      __typename
    }
    __typename
  }
}

fragment BrandSection on BrandSection {
  __typename
  title
  subHeading
  content {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

fragment SectionCallToAction on SectionCallToAction {
  itemsCollection(limit: 2) {
    items {
      ...CallToAction
      __typename
    }
    __typename
  }
  __typename
}

fragment CallToAction on CallToAction {
  __typename
  title
  ctaDescription: description
  path
  colour
}

fragment SectionFindUs on SectionFindUs {
  __typename
  title
  introduction
  subheading
  logo
  floorplan
  findUsDescription: description {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

fragment SectionGallery on SectionGallery {
  title
  rowsCollection(limit: 2) {
    items {
      __typename
      ...GalleryRow
    }
    __typename
  }
  __typename
}

fragment GalleryRow on GalleryRow {
  title
  rowHeight
  columnsCollection(limit: 3) {
    items {
      __typename
      ...ColouredGalleryItem
      ...GalleryItem
      ...ImagePanel
      ...SplitGalleryItem
    }
    __typename
  }
  __typename
}

fragment ColouredGalleryItem on ColouredGalleryItem {
  title
  color
  description {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  link
  backgroundColour
  __typename
}

fragment SplitGalleryItem on SplitGalleryItem {
  title
  color
  link
  backgroundColor
  imagesCollection {
    items {
      title
      image
      link
      __typename
    }
    __typename
  }
  __typename
}

fragment SectionImageColumn on SectionImageColumn {
  __typename
  title
  image
  leftAligned
  content {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

fragment SectionLive on SectionLive {
  __typename
  title
  subTitle
  description
  availableAt
  buttonsCollection(limit: 3) {
    items {
      ...ButtonLink
      __typename
    }
    __typename
  }
}

fragment SectionMultipleRows on SectionMultipleRows {
  title
  multipleRowsDescription: description {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  itemsCollection(limit: 2) {
    items {
      ...SectionImageColumn
      __typename
    }
    __typename
  }
  __typename
}

fragment SectionPartners on SectionPartners {
  __typename
  title
  logos
}

fragment SectionProducts on SectionProducts {
  __typename
  title
  description
  contentfulMetadata {
    tags {
      id
      __typename
    }
    __typename
  }
}

fragment SectionTheatres on SectionTheatres {
  __typename
  title
  introduction
  theatresCollection(limit: 10) {
    items {
      ...Theatre
      __typename
    }
    __typename
  }
}

fragment Theatre on Theatre {
  __typename
  title
  image
  whatsOn {
    ...WhatsOn
    __typename
  }
  description {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

fragment WhatsOn on WhatsOn {
  __typename
  title
  image
  itemsCollection {
    items {
      ...WhatsOnItem
      __typename
    }
    __typename
  }
}

fragment WhatsOnItem on WhatsOnItem {
  __typename
  title
  description
}

One of the issues I have found is with richtext. I would LOVE to use a fragment for these, but I can’t because they are always a different type based on the content type they are in. For example:

fragment BrandSection on BrandSection {
  __typename
  title
  subHeading
  content {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

When I use the playground, it says that content is of type BrandSectionContent and if I look at this fragment:

fragment SectionImageColumn on SectionImageColumn {
  __typename
  title
  image
  leftAligned
  content {
    json
    links {
      entries {
        inline {
          sys {
            id
            __typename
          }
          __typename
        }
        hyperlink {
          sys {
            id
            __typename
          }
          __typename
        }
        block {
          sys {
            id
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

it states that content is of type SectionImageColumnContent.
Is there a way of creating a fragment that I can share between all fragments for richtext editors?