1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.schemaCustomizationReducer = void 0;
|
5 | const initialState = () => {
|
6 | return {
|
7 | composer: null,
|
8 | context: {},
|
9 | fieldExtensions: {},
|
10 | printConfig: null,
|
11 | thirdPartySchemas: [],
|
12 | types: []
|
13 | };
|
14 | };
|
15 | const schemaCustomizationReducer = (state = initialState(), action) => {
|
16 | switch (action.type) {
|
17 | case `ADD_THIRD_PARTY_SCHEMA`:
|
18 | return {
|
19 | ...state,
|
20 | thirdPartySchemas: [...state.thirdPartySchemas, action.payload]
|
21 | };
|
22 | case `SET_SCHEMA_COMPOSER`:
|
23 | return {
|
24 | ...state,
|
25 | composer: action.payload
|
26 | };
|
27 | case `CREATE_TYPES`:
|
28 | {
|
29 | let types;
|
30 | if (Array.isArray(action.payload)) {
|
31 | types = [...state.types, ...action.payload.map(typeOrTypeDef => {
|
32 | return {
|
33 | typeOrTypeDef,
|
34 | plugin: action.plugin
|
35 | };
|
36 | })];
|
37 | } else {
|
38 | types = [...state.types, {
|
39 | typeOrTypeDef: action.payload,
|
40 | plugin: action.plugin
|
41 | }];
|
42 | }
|
43 | return {
|
44 | ...state,
|
45 | types
|
46 | };
|
47 | }
|
48 | case `CREATE_FIELD_EXTENSION`:
|
49 | {
|
50 | const {
|
51 | extension,
|
52 | name
|
53 | } = action.payload;
|
54 | return {
|
55 | ...state,
|
56 | fieldExtensions: {
|
57 | ...state.fieldExtensions,
|
58 | [name]: extension
|
59 | }
|
60 | };
|
61 | }
|
62 | case `PRINT_SCHEMA_REQUESTED`:
|
63 | {
|
64 | const {
|
65 | path,
|
66 | include,
|
67 | exclude,
|
68 | withFieldTypes
|
69 | } = action.payload;
|
70 | return {
|
71 | ...state,
|
72 | printConfig: {
|
73 | path,
|
74 | include,
|
75 | exclude,
|
76 | withFieldTypes
|
77 | }
|
78 | };
|
79 | }
|
80 | case `CREATE_RESOLVER_CONTEXT`:
|
81 | {
|
82 | const context = action.payload;
|
83 | return {
|
84 | ...state,
|
85 | context: {
|
86 | ...state.context,
|
87 | ...context
|
88 | }
|
89 | };
|
90 | }
|
91 | case `CLEAR_SCHEMA_CUSTOMIZATION`:
|
92 | return {
|
93 | ...initialState(),
|
94 | composer: state.composer
|
95 | };
|
96 | case `DELETE_CACHE`:
|
97 | return initialState();
|
98 | default:
|
99 | return state;
|
100 | }
|
101 | };
|
102 | exports.schemaCustomizationReducer = schemaCustomizationReducer;
|
103 |
|
\ | No newline at end of file |