Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related attribute __typename and name are different when used GraphQL API #304

Open
TaniaUdomsri opened this issue Jan 30, 2023 · 6 comments
Assignees
Labels
bug Something isn't working graphql investigation Issue under investigation v4 Strapi v4 waiting for feedback

Comments

@TaniaUdomsri
Copy link

TaniaUdomsri commented Jan 30, 2023

I have a few navigation items that have incorrect __typename and name when used GraphQL API. I'd say 3 out of 8 items are incorrect. For example, the item below has Content type Page and Entity Page layouts.
Screen Shot 2023-01-30 at 1 53 05 PM

However, when queried from the frontend. It returned as __typename Foundation and name Inclusivity. This attribute is from another navigation item.

Screen Shot 2023-01-30 at 1 54 35 PM

Here is the query I use:

query getNavigation ($name: String!) {
  renderNavigation(
    navigationIdOrSlug: $name
    type: TREE
    menuOnly: false
  ) {
    id
    title
    path
    related {
      id
      attributes {
        __typename
        ... on Component {
          name
        }
        ... on Foundation {
          name
        }
        ... on Pattern {
          name
        }
        ... on Page {
          name
        }
      }
    }
    items {
      id
      title
      path
      related {
        id
        attributes {
          __typename
          ... on Component {
            name
          }
          ... on Foundation {
            name
          }
          ... on Pattern {
            name
          }
          ... on Page {
            name
          }
        }
      }
      items {
        id
        title
        path
        related {
          id
          attributes {
            __typename
            ... on Component {
              name
            }
            ... on Foundation {
              name
            }
            ... on Pattern {
              name
            }
            ... on Page {
              name
            }
          }
        }
      }
    }
  }
}

Anything I should look into to fix this issue? Note, I have put navigation above graphQL in plugin config.

@cyp3rius
Copy link
Contributor

cyp3rius commented Apr 4, 2023

Checking

@cyp3rius cyp3rius self-assigned this Apr 4, 2023
@cyp3rius cyp3rius added bug Something isn't working investigation Issue under investigation v4 Strapi v4 graphql labels Apr 4, 2023
@cyp3rius
Copy link
Contributor

cyp3rius commented Apr 6, 2023

@TaniaUdomsri I'm trying to reproduce your issue but I can't get to the state with mixed types you provided.

  renderNavigation(
    navigationIdOrSlug: "main-navigation"
    type: TREE
    menuOnly: false
  ) {
    id
    title
    path
    related {
      id
      attributes {
        __typename

        ... on Page {
          Title
        }

        ... on WithFlowType {
          Name
        }

        ... on NoFlowType {
          Name
        }
      }
    }
    items {
      id
      title
      path
      items {
        id
        title
        path
        related {
          id
          attributes {
            __typename

            ... on Page {
              Title
            }

            ... on WithFlowType {
              Name
            }

            ... on NoFlowType {
              Name
            }
          }
        }
      }
      related {
        id
        attributes {
          __typename

          ... on Page {
            Title
          }

          ... on WithFlowType {
            Name
          }

          ... on NoFlowType {
            Name
          }
        }
      }
    }
  }
}

Response

  "data": {
    "renderNavigation": [
      {
        "id": 1,
        "title": "Test",
        "path": "/test",
        "related": {
          "id": 1,
          "attributes": {
            "__typename": "Page",
            "Title": "Test page"
          }
        },
        "items": [
          {
            "id": 2,
            "title": "External item",
            "path": "https://example.com",
            "items": null,
            "related": null
          },
          {
            "id": 3,
            "title": "Another",
            "path": "/test/another",
            "items": [
              {
                "id": 6,
                "title": "Nested",
                "path": "/test/another/test",
                "related": {
                  "id": 4,
                  "attributes": {
                    "__typename": "Page",
                    "Title": "Nested page"
                  }
                }
              },
              {
                "id": 7,
                "title": "Another nested",
                "path": "/test/another/another-nested",
                "related": {
                  "id": 5,
                  "attributes": {
                    "__typename": "Page",
                    "Title": "another nested page"
                  }
                }
              },
              {
                "id": 8,
                "title": "With flow",
                "path": "/test/another/with-flow",
                "related": {
                  "id": 1,
                  "attributes": {
                    "__typename": "WithFlowType",
                    "Name": "Test with flow"
                  }
                }
              }
            ],
            "related": {
              "id": 2,
              "attributes": {
                "__typename": "Page",
                "Title": "Another page"
              }
            }
          },
          {
            "id": 5,
            "title": "Yet another page",
            "path": "/test/yet-another",
            "items": [
              {
                "id": 11,
                "title": "Blog post",
                "path": "/test/yet-another/post-1",
                "related": {
                  "id": 1,
                  "attributes": {
                    "__typename": "BlogPost"
                  }
                }
              },
              {
                "id": 10,
                "title": "blog post 2",
                "path": "/test/yet-another/post-2",
                "related": {
                  "id": 2,
                  "attributes": {
                    "__typename": "BlogPost"
                  }
                }
              }
            ],
            "related": {
              "id": 3,
              "attributes": {
                "__typename": "Page",
                "Title": "And yet another"
              }
            }
          }
        ]
      }
    ]
  }
}```

Is this still happening? Your query looks proper.

@TaniaUdomsri
Copy link
Author

Hi @cyp3rius,

Thanks for taking a look at the issue. Yes, this is still happening. I understand this is a super weird bug. I'd like to point out this is only happening while using Apollo's useQuery hook. However, the data returns correctly while testing on GraphQL playground.

@cyp3rius
Copy link
Contributor

cyp3rius commented Apr 6, 2023

So I think the difference and possible issue might be somewhere in the Apollo hook itself, some kind of configuration or properties of it. Have you played a bit with it?

@TaniaUdomsri
Copy link
Author

TaniaUdomsri commented Apr 6, 2023

I've been trying to use useLazyQuery instead to wait for other queries and components to finished with no luck. Not sure what else to look for or where to start in this case. We have been using it for other queries for Strapi without any issues. Any advice?

@c3s4
Copy link

c3s4 commented Jul 26, 2023

Hi,
the same thing happened to me, I digged into database and everything was ok, then, as suggested here, I tried to issue the query manually (using playground) and the response is totally fine.

I'm not using the hook but the query method of the ApolloClient class. There I can use an option to disable caching and i worked.

This option

fetchPolicy: "no-cache",

as value in the option object, fixed this problem.

To be honest I haven't figured it out yet why this happen, I just have some thoughts.

Hope this help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graphql investigation Issue under investigation v4 Strapi v4 waiting for feedback
Projects
None yet
Development

No branches or pull requests

3 participants