apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

is possible nested fragments query in apollo client? it is can in apollo studio. #11182

Closed dev-yesman closed 1 year ago

dev-yesman commented 1 year ago

Need help or want to talk all things Apollo Client? Issues here are reserved for bugs, but one of the following resources should help:

Hello, I am a frontend developer working with Apollo Client and graphql-codegen to use GraphQL. In Apollo Studio, when I write the query below, it fetches the values correctly. However, strangely enough, when I craft the query in the frontend code using Apollo Client (graphql-tag), it doesn't work as expected. Is this the intended behavior? Or could it be a bug with Apollo Client or graphql-tag?

fragment SitemapFields_Sitemap on Sitemap {
  __typename
  id
  title
}

fragment CommonMenu_iMenu on IMenu {
  id
  title
  description
  sitemap {
    id
    title
  }
  parent {
    id
    title
  }
}

fragment boardMenuFields_BoardMenu on BoardMenu {
  __typename
  id
  permissionViewMenuGroups {
    id
    title
  }
  board {
    id
    title
    slug
    description
    isMentorBoard
  }
}

fragment simpleMenuFields_SimpleMenu on SimpleMenu {
  __typename
  id
  permissionViewMenuGroups {
    id
    title
  }
}

fragment shortcutMenuFields_ShortcutMenu on ShortcutMenu {
  __typename
  id
  url
  permissionViewMenuGroups {
    id
    title
  }
}

fragment OnMenu_iMenu on IMenu {
  ...CommonMenu_iMenu
  ... on BoardMenu {
    ...boardMenuFields_BoardMenu
  }
  ... on SimpleMenu {
    ...simpleMenuFields_SimpleMenu
  }
  ... on ShortcutMenu {
     ...shortcutMenuFields_ShortcutMenu
  }
}

query gqlCommunitySitemaps {
  sitemaps {
    nodes {
      ...SitemapFields_Sitemap
      children {
        ...OnMenu_iMenu
        children {
          ...OnMenu_iMenu
          children {
            ...OnMenu_iMenu
            children {
              ...OnMenu_iMenu
              children {
                ...OnMenu_iMenu
                children {
                  ...OnMenu_iMenu
                }
              }
            }
          }
        }
      }
    }
  }
}
### Tasks
### Tasks
phryneas commented 1 year ago

I suspect some of these are interfaces, and you are not passing possibleTypes?

Can you take a look at https://www.apollographql.com/docs/react/data/fragments/#using-fragments-with-unions-and-interfaces and see if that solves your problem?

github-actions[bot] commented 1 year ago

We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.