-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-mutation-server.js
More file actions
36 lines (28 loc) · 938 Bytes
/
update-mutation-server.js
File metadata and controls
36 lines (28 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { mutationWithClientMutationId, fromGlobalId } from 'graphql-relay';
import { WidgetData } from '../models/widget-data';
import { Viewer, Widget } from '../models/graphql-models';
import { updateWidgetType } from './widget-input-types';
import { viewerType } from './viewer-type';
import { widgetType } from './widget-type';
export const updateWidgetMutationType = mutationWithClientMutationId({
name: 'UpdateWidget',
inputFields: {
widget: {
type: updateWidgetType
}
},
outputFields: {
viewer: {
type: viewerType,
resolve: () => Object.assign(new Viewer(), { id: 1 }),
},
widget: { type: widgetType },
},
mutateAndGetPayload: ({ widget }, { baseUrl }) => {
widget.id = fromGlobalId(widget.id).id;
const widgetData = new WidgetData(baseUrl);
return widgetData.update(widget).then(widget =>
({ widget: Object.assign(new Widget(), widget) })
);
},
});