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

Some UnionType fragments are not triggering the correct loading state for additional queries. #857

Closed
acorcutt opened this issue Oct 30, 2016 · 5 comments

Comments

@acorcutt
Copy link

Its only showing a loading state when fetching the 1st fragment from a union, is this related to what is being fixed in #707 or is the loading state looking at the wrong fragment. Data is loaded correctly for all types and re-ordering changes things...

Site is a union...

export default new GraphQLUnionType({
  name: 'Site',
  types: () => ([TeamType, MemberType])
});

1st query triggers loading state as expected for either type...

graphql(gql`
  query ParentQuery {
    site {
      __typename
      ... on Team {        
        id
        name
      }    
      ... on Member {        
        id
        name
      }    
    }
  }`)(Parent);

2nd query from child of root triggers loading state when returned type is a Team but not Member...

graphql(gql`
  query ChildQuery {
    site {
      __typename
      ... on Team {        
        id
        name
        summary
      }    
      ... on Member {        
        id
        name
        summary
      }    
    }
  }`)(Child);

Re-ordering the fragments triggers loading state when type is a Member but not a Team...

graphql(gql`
  query ChildQuery {
    site {
      __typename
      ... on Member {        
        id
        name
        summary
      }    
      ... on Team {        
        id
        name
        summary
      }    
    }
  }`)(Child);
@helfer
Copy link
Contributor

helfer commented Oct 31, 2016

@acorcutt Thanks for bringing this up. Are you using version 0.5.0 of Apollo Client? And is __typename added to the query (i.e. do you have addTypename set to true (or at least not to false))?

FWIW I don't think this is related to #707. It seems to be related to fragment handling instead.

@acorcutt
Copy link
Author

I've tried both with & without addTypename and my id's are globally unique from the relay node interface, versions: [email protected] & [email protected]

I'm thinking it is the fragment matching now, I'm not seeing it batch any queries with fragments - #771 suggests there is no matching on unions?

@helfer
Copy link
Contributor

helfer commented Oct 31, 2016

As long as there is no data there initially, Apollo Client should show the loading state regardless of what type the returned object is going to be. And given __typename, I see no reason why Apollo Client wouldn't be able to figure out which fragment applies.

@stubailo what's the status on supporting this simple case of union types from the example above in graphql-anywhere?

@helfer
Copy link
Contributor

helfer commented Jan 26, 2017

@acorcutt is this still an issue with the latest version?

@helfer
Copy link
Contributor

helfer commented May 3, 2017

This should be fixed with #1483.

@helfer helfer closed this as completed May 3, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants