Graphile Config Preset
A preset bundles together a list of plugins, and options for various of the
"scopes". You may use more than one preset at a time, and presets may also
compose (extend) other presets. When a library is passed a list of presets it
results in a resolved preset (a preset that has no "extends") using the
ResolvePresets
algorithm; broadly all the extends
are resolved in order, the
plugins specified are merged as a set (each plugin will only be included once)
and the options are merged via object merging such that the options specified
last win.
NOTE: if you compose two presets (PresetA and PresetB) that both extends
the same underlying preset (BASE) and apply some overrides, then the overrides
in PresetA will be overridden by re-applying the BASE preset again. For this
reason, presets that are expected to be combined with other presets should not
extends
common/shared presets, instead the end-user should be expected to add
these presets themselves.
NOTE: the order of presets is significant.
ResolvePresets(presets):
- Let {finalPreset} be an empty preset.
- For each {preset} in {presets}:
- Let {resolvedPreset} be {ResolvePreset(preset)}.
- Let {finalPreset} be {MergePreset(finalPreset, resolvedPreset)}.
- Return {finalPreset}.
ResolvePreset(preset):
- Let {presets} be the list specified in the {extends} property of {preset} (or an empty list if none specified).
- Let {basePreset} be {ResolvePresets(presets)}.
- Return {MergePreset(basePreset, preset)}.
MergePreset(basePreset, extendingPreset):
- Let {finalPreset} be an empty preset.
- Assert: {basePreset} has an empty or non-existent {extends} property.
- Let {plugins} be the list of plugins defined in {basePreset} union the list of plugins in {extendingPreset}.
- Let the list of plugins for {finalPreset} be {plugins}.
- Let {scopes} be the list of scopes defined in {basePreset} union the list of scopes in {extendingPreset}.
- For each {scope} in {scopes}:
- Let {baseScope} be the {scope} in {basePreset}.
- Let {extendingScope} be the {scope} in {extendingPreset}.
- If {baseScope} and {extendingScope} both exist:
- Let {scope} in {finalPreset} be the result of merging {baseScope} and
{extendingScope} akin to
Object.assign({}, baseScope, extendingScope)
.
- Let {scope} in {finalPreset} be the result of merging {baseScope} and
{extendingScope} akin to
- Else: let {scope} in {finalPreset} be whichever of {baseScope} and {extendingScope} actually exist.
- Return {finalPreset}.
IMPORTANT: the default
name must not be used as a top-level key in a
preset to enable compatibility with the various ESM emulations.