You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have set up some batch DataLoaders for each entity (that have relationships with others) in order to solve the N+1 Problem with GraphQL/SPQR - and it works. HOWEVER, when I have a @OneToOne or @ManyToMany relation on some entity that is null, an Exception while fetching data (/getAllEmployees[6]/company) : null.
Here is the resolver for the company field of each employee:
@Setter@Getter@Entity@NoArgsConstructor@AllArgsConstructorpublicclassEmployeeimplementsSerializable {
privatestaticfinallongserialVersionUID = 684733882540759135L;
@Id@GeneratedValue@Column(columnDefinition = "uuid", updatable = false)
@GraphQLQuery(name = "id", description = "A Person's Id")
privateUUIDid;
@NotNull(message = "There must be a Person's Name!")
@GraphQLQuery(name = "fullName", description = "A Person's Name")
privateStringfullName;
@NotNull(message = "A Person must have an Age!")
@GraphQLQuery(name = "age", description = "A Person's Age")
privateintage;
@NotNull(message = "A Person must have a Vehicle!")
@GraphQLQuery(name = "personalVehicle", description = "A Person's Mode of Transport")
privateVehiclepersonalVehicle;
@ManyToOne(targetEntity = Company.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@GraphQLQuery(name = "company", description = "The Company a Person works for")
privateCompanycompany;
@GraphQLQuery(name = "roles", description = "The Role a Person plays in their Company")
@OneToMany(
targetEntity = Role.class,
orphanRemoval = true,
fetch = FetchType.LAZY,
mappedBy = "employee",
cascade = CascadeType.ALL)
privateList<Role> roles = newArrayList<>();
publicenumVehicle {
CAR,
BUS,
VAN,
BICYCLE,
MOTORBIKE,
SCOOTER
}
}
For the Company
@Setter@Getter@Entity@NoArgsConstructor@AllArgsConstructorpublicclassCompanyimplementsSerializable {
privatestaticfinallongserialVersionUID = -6007975840330441233L;
@Id@GeneratedValue@Column(columnDefinition = "uuid", updatable = false)
@GraphQLQuery(name = "id", description = "A Company's Id")
privateUUIDid;
@NotNull(message = "There must be a Company Name!")
@GraphQLQuery(name = "name", description = "A Company's Name")
privateStringname;
@Min(10000)
@NotNull(message = "You gotta tell us how rich you are!")
@GraphQLQuery(name = "balance", description = "A Company's Dollar")
privateBigDecimalbalance;
@NotNull(message = "There must be a Company Type!")
@GraphQLQuery(name = "type", description = "The type of company")
privateCompanyTypetype;
@GraphQLQuery(name = "offices", description = "The Company's offices")
@OneToMany(
targetEntity = Office.class,
orphanRemoval = true,
fetch = FetchType.LAZY,
mappedBy = "company",
cascade = CascadeType.ALL)
privateList<Office> offices;
publicenumCompanyType {
PRIVATE_LIMITED,
SOLE_TRADER,
PUBLIC
}
}
Any help, comments or clarification would be much, much appreciated - I'm probably missing out something stupid!!
The text was updated successfully, but these errors were encountered:
@kaqqao @ellebrecht @jestan @heruan @vojtechhabarta Hi all,
I have set up some batch DataLoaders for each entity (that have relationships with others) in order to solve the N+1 Problem with GraphQL/SPQR - and it works. HOWEVER, when I have a
@OneToOne
or@ManyToMany
relation on some entity that is null, anException while fetching data (/getAllEmployees[6]/company) : null
.Here is the resolver for the company field of each employee:
And the DataFetcher,
And for some context, here are the entities:
For the Employee
For the Company
Any help, comments or clarification would be much, much appreciated - I'm probably missing out something stupid!!
The text was updated successfully, but these errors were encountered: