【发布时间】:2021-07-06 13:57:48
【问题描述】:
堆栈:
- VueJS/Vuetify
- Apollo 客户端
- Spring Boot、MongoDB 和 GraphQL 服务器
我面临的问题是,当我使用 Apollo 执行我的 GraphQL 查询并且有一组引用实体时,抓取所有字段除了id 工作正常,但尽快正如我添加的那样
id {
entityId
organisationId
}
为了还获得id 字段,它返回所有相同实体的集合。
假设有三个用户:John、Jane 和 Jen;具体按这个顺序。当我执行查询时,它将返回 3 次 John 的对象,当 id 在 GraphQL 查询中时。如果 id 不在 GraphQL 查询中,它将正确返回所有实体。
当我通过 Postman 执行查询时,它可以正常工作。这似乎是 Apollo 特定的问题。
id 实体:
public class TradelyId implements Serializable {
String entityId;
String organisationId;
}
一些可能有助于描绘画面的 sn-ps:
@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!]!
}
【问题讨论】:
-
如果我错过了任何可能有帮助的信息,请随时提出。
-
apollographql.com/docs/react/caching/cache-configuration/… ... IDK 如果 vue apollo 支持
-
@xadm 感谢您的回复,这正是我想要的。一旦我找出答案,我会在这里发布并提及你。
标签: graphql apollo-client