Files
30-seconds-of-code/node_modules/gatsby/dist/redux/reducers/schema-customization.js
2019-08-20 15:52:05 +02:00

98 lines
2.1 KiB
JavaScript

"use strict";
module.exports = (state = {
composer: null,
context: {},
fieldExtensions: {},
printConfig: null,
thirdPartySchemas: [],
types: []
}, action) => {
switch (action.type) {
case `ADD_THIRD_PARTY_SCHEMA`:
return Object.assign({}, state, {
thirdPartySchemas: [...state.thirdPartySchemas, action.payload]
});
case `SET_SCHEMA_COMPOSER`:
return Object.assign({}, state, {
composer: action.payload
});
case `CREATE_TYPES`:
{
let types;
if (Array.isArray(action.payload)) {
types = [...state.types, ...action.payload.map(typeOrTypeDef => {
return {
typeOrTypeDef,
plugin: action.plugin
};
})];
} else {
types = [...state.types, {
typeOrTypeDef: action.payload,
plugin: action.plugin
}];
}
return Object.assign({}, state, {
types
});
}
case `CREATE_FIELD_EXTENSION`:
{
const {
extension,
name
} = action.payload;
return Object.assign({}, state, {
fieldExtensions: Object.assign({}, state.fieldExtensions, {
[name]: extension
})
});
}
case `PRINT_SCHEMA_REQUESTED`:
{
const {
path,
include,
exclude,
withFieldTypes
} = action.payload;
return Object.assign({}, state, {
printConfig: {
path,
include,
exclude,
withFieldTypes
}
});
}
case `CREATE_RESOLVER_CONTEXT`:
{
const context = action.payload;
return Object.assign({}, state, {
context: Object.assign({}, state.context, context)
});
}
case `DELETE_CACHE`:
return {
composer: null,
context: {},
fieldExtensions: {},
printConfig: null,
thirdPartySchemas: [],
types: []
};
default:
return state;
}
};
//# sourceMappingURL=schema-customization.js.map