The stack:
- VueJS/Vuetify
- Apollo client
- Spring boot, MongoDB and GraphQL server
The issue I'm facing is, when I execute my GraphQL query using Apollo and there is a collection of referenced entities, grabbing all the fields except the id
works fine, but as soon as I add
id {
entityId
organisationId
}
to also get the id
fields, it returns a collection of all the same entity.
Let's say there is three users: John, Jane and Jen; specifically in this order. When I execute the query, it will return John
's object three times, when the id
is in the GraphQL query. If the id
isn't in the GraphQL query, it will return all the entities correctly.
When I execute the query through Postman, it works correctly. It seems to be an Apollo specific issue.
The id
entity:
public class TradelyId implements Serializable {
String entityId;
String organisationId;
}
A few snippets that might help paint the picture:
@Document
@Getter
@Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
public class Assignment implements Serializable {
private static final long serialVersionUID = -165856150537588143L;
@Id
@NotNull
@NonNull
@EqualsAndHashCode.Include
private TradelyId id;
@NotNull
@NonNull
private Instant startDateTime;
@NotNull
@NonNull
private Instant endDateTime;
@NotNull
@NonNull
@DBRef
@ShallowReference
private Job job;
@NotNull
@NonNull
@DBRef(lazy = true)
@ShallowReference
private List<User> users = new ArrayList<>();
}
type Assignment {
id: TradelyId!
startDateTime: String!
endDateTime: String!
job: Job!
users: [User!]!
}
input AssignmentRefInput {
id: TradelyIdQueryInput!
}
input AssignmentCreateInput {
id: TradelyIdCreateInput!
startDateTime: String!
endDateTime: String!
job: JobRefInput!
users: [UserRefInput!]!
}
input AssignmentUpdateInput {
id: TradelyIdQueryInput!
startDateTime: String!
endDateTime: String!
job: JobRefInput!
users: [UserRefInput!]!
}
extend type Mutation {
createAssignment(assignment: AssignmentCreateInput!): TradelyId!
updateAssignment(assignment: AssignmentUpdateInput!): TradelyId!
}
extend type Query {
assignment(id: TradelyIdQueryInput!): Assignment
assignments(id: String!): [Assignment!]!
assignmentForJobId(id: TradelyIdQueryInput!): Assignment
usersAvailableForAssignment(startDateTime: String!, endDateTime: String!): [User!]!
assignmentsForUser: [Assignment!]!
}