Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
761dd17c
Commit
761dd17c
authored
Oct 16, 2020
by
Nicolò Maria Mezzopera
Committed by
Natalia Tepluhina
Oct 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Immutable cache update in `submit_content_changes` resolver
parent
a7248d86
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
11 deletions
+52
-11
app/assets/javascripts/static_site_editor/graphql/index.js
app/assets/javascripts/static_site_editor/graphql/index.js
+1
-0
app/assets/javascripts/static_site_editor/graphql/resolvers/has_submitted_changes.js
...ic_site_editor/graphql/resolvers/has_submitted_changes.js
+14
-6
app/assets/javascripts/static_site_editor/graphql/resolvers/submit_content_changes.js
...c_site_editor/graphql/resolvers/submit_content_changes.js
+10
-5
spec/frontend/static_site_editor/graphql/resolvers/has_submitted_changes_spec.js
...te_editor/graphql/resolvers/has_submitted_changes_spec.js
+27
-0
No files found.
app/assets/javascripts/static_site_editor/graphql/index.js
View file @
761dd17c
...
...
@@ -21,6 +21,7 @@ const createApolloProvider = appData => {
},
{
typeDefs
,
assumeImmutableResults
:
true
,
},
);
...
...
app/assets/javascripts/static_site_editor/graphql/resolvers/has_submitted_changes.js
View file @
761dd17c
import
{
produce
}
from
'
immer
'
;
import
query
from
'
../queries/app_data.query.graphql
'
;
const
hasSubmittedChangesResolver
=
(
_
,
{
input
:
{
hasSubmittedChanges
}
},
{
cache
})
=>
{
const
{
appData
}
=
cache
.
readQuery
({
query
});
cache
.
writeQuery
({
query
,
data
:
{
const
oldData
=
cache
.
readQuery
({
query
});
const
data
=
produce
(
oldData
,
draftState
=>
{
// punctually modifying draftState as per immer docs upsets our linters
return
{
...
draftState
,
appData
:
{
__typename
:
'
AppData
'
,
...
appData
,
...
draftState
.
appData
,
hasSubmittedChanges
,
},
},
};
});
cache
.
writeQuery
({
query
,
data
,
});
};
...
...
app/assets/javascripts/static_site_editor/graphql/resolvers/submit_content_changes.js
View file @
761dd17c
import
{
produce
}
from
'
immer
'
;
import
submitContentChanges
from
'
../../services/submit_content_changes
'
;
import
savedContentMetaQuery
from
'
../queries/saved_content_meta.query.graphql
'
;
...
...
@@ -14,14 +15,18 @@ const submitContentChangesResolver = (
images
,
mergeRequestMeta
,
}).
then
(
savedContentMeta
=>
{
cache
.
writeQuery
({
query
:
savedContentMetaQuery
,
data
:
{
const
data
=
produce
(
savedContentMeta
,
draftState
=>
{
return
{
savedContentMeta
:
{
__typename
:
'
SavedContentMeta
'
,
...
savedContentMeta
,
},
...
draftState
,
},
};
});
cache
.
writeQuery
({
query
:
savedContentMetaQuery
,
data
,
});
});
};
...
...
spec/frontend/static_site_editor/graphql/resolvers/has_submitted_changes_spec.js
0 → 100644
View file @
761dd17c
import
appDataQuery
from
'
~/static_site_editor/graphql/queries/app_data.query.graphql
'
;
import
hasSubmittedChanges
from
'
~/static_site_editor/graphql/resolvers/has_submitted_changes
'
;
describe
(
'
static_site_editor/graphql/resolvers/has_submitted_changes
'
,
()
=>
{
it
(
'
updates the cache with the data passed in input
'
,
()
=>
{
const
cachedData
=
{
appData
:
{
original
:
'
foo
'
}
};
const
newValue
=
{
input
:
{
hasSubmittedChanges
:
true
}
};
const
cache
=
{
readQuery
:
jest
.
fn
().
mockReturnValue
(
cachedData
),
writeQuery
:
jest
.
fn
(),
};
hasSubmittedChanges
(
null
,
newValue
,
{
cache
});
expect
(
cache
.
readQuery
).
toHaveBeenCalledWith
({
query
:
appDataQuery
});
expect
(
cache
.
writeQuery
).
toHaveBeenCalledWith
({
query
:
appDataQuery
,
data
:
{
appData
:
{
__typename
:
'
AppData
'
,
original
:
'
foo
'
,
hasSubmittedChanges
:
true
,
},
},
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment