UpdateQueries with inline fragments fails
See original GitHub issueI have a query that looks something like this:
query getGraph {
nodes {
...NodeContent
}
}
${nodeFragment}
where nodeFragment
is:
fragment NodeContent on Node {
id
type
x
y
... on TriggerNode {
properties {
trigger
}
}
... on ReplyNode {
properties {
reply
keep
}
}
}
This runs fine, and I get back the desired result.
I then want to perform a mutation that adds a node, and therefore runs updateQueries
. So I wrote a query like this:
mutation createNode ($type:String!, $x:Int!, $y:Int!, $properties:PropertiesInput!) {
createNode(type:$type, x:$x, y:$y, properties:$properties) {
...NodeContent
}
}
${nodeFragment}
And called it like this:
const withCreateNodeMutation = graphql(createNodeMutation, {
props: ({ mutate }) => ({
createNode: variables => mutate({
variables,
updateQueries: {
getGraph: () => { console.log('hello world'); },
},
}),
}),
});
Intended outcome:
I expected the client to at least run the updateQueries
function and print hello world
in the console.
Actual outcome:
Nothing happens!
Interestingly, I am getting back the correct, complete result in the APOLLO_MUTATION_RESULT
action (with the correct __typename
s on the fragments and everything). The updateQueries
function is just not called.
This also makes optimistic UI impossible.
Could be related to #1363, #1379?
Would appreciate any thoughts or workarounds - perhaps the new imperative API? Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (8 by maintainers)
Top GitHub Comments
@Mike-Dax I upgraded to
react-apollo@1.0.0
(and thereforeapollo-client@1.0.1
), and also passed my schema intofragmentMatcher
on the apollo client options but it seems to have made no difference.updateQueries
is still never called (noconsole.log
). I traced this through Chrome’s debugger: it seems thatcontext.hasMissingField
is being set totrue
duringdiffQueryAgainstStore
, causing it to short circuit out ofupdateQueries
. I’m afraid I don’t know enough about that code to be able to help on that front further!If I use
update
, I can update the store fine (looking at thenext state
via theAPOLLO_MUTATION_RESULT
reducer shows the correct updated store), but it won’t update the props passed down into my component that uses the updated query.The only reliable option still seems to be
refetchQueries
.@msimulcik Sorry for the delay: I’ve produced a minimal example repo here: https://github.com/benhjames/apollo-fragment-issue
The most important thing about this is that if you remove the
... on ReplyNode
and... on TriggerNode
fragments from the query/mutation, it works just fine. As soon as you add in the fragments, the client stops callingupdateQueries
etc.Interestingly, somewhere between
apollo-client@1.0.0-rc3
andapollo-client@1.0.0
,refetchQueries
also stopped working.Do let me know if there’s anything else you need info-wise. Cheers 😃