Skip to content

Missing fields from projection in addRelation #377

Open
@trollcus

Description

@trollcus

Hi!

I'm having issues with the addRelation function. More specifically when projecting fields towards the graphql request. Worth noting is that this worked with the use of composeWithMongoose function previously.

Setup:

graphql-compose: "^9.0.3"
graphql-compose-mongoose: "^9.6.0"
mongoose: "5.13.8"

Code:

export const PrevisitSchema = new Schema(
  {
    project_id: { type: Schema.Types.ObjectId, required: true },
// ...
  },
  {
    collection: 'previsits',
  }
)

export const Previsit = mongoose.model('Previsit', PrevisitSchema)
export const PrevisitTC = composeMongoose(Previsit)

PrevisitTC.addRelation('project', {
  resolver: () => ProjectTC.mongooseResolvers.dataLoader({ lean: true }),
  prepareArgs: {
    _id: source => source.project_id || null,
  },
  projection: { project_id: 1 },
})

To further clarify.

query {
  previsitMany {
    project_id
    project {
      _id
    }
  }
}

Works while:

query {
  previsitMany {
    project {
      _id
    }
  }
}

does not

All that I get from source is the field _id and it all results in that the project field is null. Any other field I query is undefined. Any ideas to why?

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