Jim
05/09/2018, 5:59 AMtype Location {
id: ID! @unique
name: String!
users: [User!]!
}
type User {
id: ID! @unique
name: String!
location: Location
}
Im displaying the users at each location:
export const LOCATION_QUERY = gql`
query LocationQuery($machineName: String!) {
location(machineName: $machineName) {
id
name
machineName
users {
id
}
}
}
`;
When a user joins a location the previous query gets updated automatically:
const JOIN_LOCATION = gql`
mutation joinLocation($userId: ID!, $locationMachine: String!) {
joinLocation(userId: $userId, locationMachine: $locationMachine) {
id
location {
id
users {
id
}
}
}
}
`;
But when they leave a location the query doesnt update:
const LEAVE_LOCATION = gql`
mutation leaveLocation($userId: ID!) {
leaveLocation(userId: $userId) {
id
location {
id
users {
id
}
}
}
}
`;
I think this is because the location field returns emptry so Apollo doesnt know that the number of users has changed. Is there an elegant solution to this? I could manually write to the store but I thoguth id check if there was a better way first.nilan
05/10/2018, 1:48 PM