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

Fragments not working - missing fields in root #91

Closed
maticzav opened this issue Jan 29, 2018 · 8 comments
Closed

Fragments not working - missing fields in root #91

maticzav opened this issue Jan 29, 2018 · 8 comments
Labels

Comments

@maticzav
Copy link

Expected behaviour:

Fields defined in fragments are automatically prepended to info query.

Actual behaviour:

Fields defined in fragments are not automatically prepended to info query, which causes certain resolvers to return wrong data.

Recreation:

query {
  homesInPriceRange(min: 0, max: 9000) {
    name
    numRatings
  }
}
  • numRatings is always zero, because id is undefined.
  numRatings: {
    fragment: `fragment NumRatings on Place { id }`,
    resolve: async (parent, args, ctx: Context, info) => {
      console.log(parent);
      
      const reviews = await ctx.db.query.reviewsConnection(
        { where: { place: { id: parent.id } } },
        `{ aggregate { count } }`,
      )
      return reviews.aggregate.count
    },
  },

Example of parent log:

{ name: 'Romantic, Cozy Cottage Next to Downtown' }
@kbrandwijk
Copy link
Contributor

Did you use extractFragments?

@marktani
Copy link
Contributor

Yes.

@maticzav
Copy link
Author

Yes, this is a copy of this example, with the only change in console.log.

@marktani
Copy link
Contributor

marktani commented Feb 2, 2018

Looks to be caused by this one: ardatan/graphql-tools#605

@schickling
Copy link
Contributor

@marktani I think this is a different issue.

@maticzav can you confirm this is still a problem for you? We've recently introduced some bug fixes around this topic.

@maticzav
Copy link
Author

@schickling seems like it's working now! Great job 🙂

@lnmunhoz
Copy link

@maticzav I can't get this working. What package versions are you using?

@maticzav
Copy link
Author

Hey @lnmunhoz 👋,

I am using GraphQL Yoga 1.16.2. If you make a reproduction repo, I can help you figure this out! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants