cashay
cashay copied to clipboard
mutation selectors should not include @live fields
If you have a mutation that returns an object (not a scalar), e.g.
schema {
mutation: {
updateProject: Project
cashay will build the mutation to select fields for that type to fulfill any active queries.
but cashay seems to ignore @live directives (and possibly @cached as well?)
e.g. if you have a query
project (id: $project_id) @live {
id
name
projectTodos @live {
id
description
}
}
when you run the mutation
cashay.mutate('updateProject', ...
cashay sends this to the server:
mutation ($id: ID!, $name: String!) {
updateProject(id: $id, name: $name) {
projectTodos @live {
id
description
}
id
name
}
}
which causes graphql to throw: Unknown directive "live".
when using mutations on live data, i have that mutation return a GraphQLBoolean or similar. The reason why is because if it's live, then you aren't going to respond directly, rather the response is going to come from your pubsub. otherwise, you'd be getting 2 results (1 for the requesting client, and another being the requesting entity is subscribed to that pubsub channel)
@mattkrick thanks, yeah i figured that much out. i do think there should be an error from cashay for such a mutation that selects live fields—but feel free to close if that's more of a roadmap thing
yeah, v2 i'm just gonna scrap the mutation-writing heuristic, which will solve this. it was cute, but annoying, specifically for this bug that lies in the graphql package (i still think calling a mutation w/o wanting anything back is useful & the fact that graphql disallows that is silly IMO).