Skip to content

Instantly share code, notes, and snippets.

@tricoder42
Created September 4, 2018 10:02
Show Gist options
  • Save tricoder42/d15bcfb719c68dfcbb0318ca3a58c98f to your computer and use it in GitHub Desktop.
Save tricoder42/d15bcfb719c68dfcbb0318ca3a58c98f to your computer and use it in GitHub Desktop.
  1. Query projectIssue is resolved with an object "IssueType:18"
  2. Mutation issueEdit is called and returns the same object with updated attachments
  3. Object "IssueType:18" is updated correctly in cache (checked in Apollo DevTool and also manually by store.readFragment)
  4. Query projectIssue reloaded from cache automatically, but this this it doesn't return object

In Apollo DevTool I see this field in root query: issue({"issueId":"18","project":"IEP001"}): IssueType:18. I believe the query should be updated when object IssueType:18 in cache is updated, but when it happens, the object is empty.

fragment Issue on IssueType {
id
issueId
urgency
importance
priority
content
isOpen
assignedTo {
id
key
fullName
}
__typename
}
mutation issueEdit($id: ID!, $attachments: [Upload]) {
issueEdit(id: $id, attachments: $attachments) {
ok
error
issue {
...Issue
attachments {
id
name
url
}
}
}
}
import { graphql } from 'react-apollo'
import mutation from './mutation.graphql'
import gql from 'graphql-tag'
export default graphql(mutation, {
props: ({ mutate }) => ({
mutation(id, variables) {
return mutate({
variables: {
...variables,
id,
}
})
},
}),
})
query projectIssue ($project: String!, $issueId: Int!) {
issue(project: $project, issueId: $issueId) {
...Issue
attachments {
...Attachment
}
}
}
import { graphql } from 'react-apollo'
import { evolve, filter } from 'ramda'
import query from './query.graphql'
export default graphql(query, {
options: props => ({
variables: {
project: props.match.params.projectKey,
issueId: props.match.params.issueId,
},
fetchPolicy: 'cache-and-network',
}),
props: ({ data }) =>
console.log(data.issue) || {
issue: data.issue || {},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment