Skip to content

Fragments not working - missing fields in root #91

@maticzav

Description

@maticzav

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' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions