@@ -52,6 +52,17 @@ export async function resolveConfigStrategy(source, _id, strategy, operation, ac
5252 return strategies ;
5353}
5454
55+ export async function resolveRelay ( source , context ) {
56+ const relay = source . relay ;
57+ const environment = context . environment ? context . environment : EnvType . DEFAULT ;
58+
59+ if ( ! relay . type || ! relay . activated [ environment ] || ! relay . endpoint [ environment ] ) {
60+ return null ;
61+ }
62+
63+ return relay ;
64+ }
65+
5566export async function resolveConfig ( source , _id , key , activated , context ) {
5667 const args = { } ;
5768
@@ -62,7 +73,7 @@ export async function resolveConfig(source, _id, key, activated, context) {
6273 let configs = await Config . find ( { group : source . _id , ...args } ) . lean ( ) . exec ( ) ;
6374
6475 if ( activated !== undefined ) {
65- configs = configs . filter ( config => config . activated [ context . environment || EnvType . DEFAULT ] === activated ) ;
76+ configs = configs . filter ( config => isElementActive ( config , context . environment , activated ) ) ;
6677 }
6778
6879 try {
@@ -87,7 +98,7 @@ export async function resolveGroupConfig(source, _id, name, activated, context)
8798 let groups = await GroupConfig . find ( { domain : source . _id , ...args } ) . lean ( ) . exec ( ) ;
8899
89100 if ( activated !== undefined ) {
90- groups = groups . filter ( group => group . activated [ context . environment || EnvType . DEFAULT ] === activated ) ;
101+ groups = groups . filter ( group => isElementActive ( group , context . environment , activated ) ) ;
91102 }
92103
93104 try {
@@ -119,7 +130,7 @@ export async function resolveDomain(_id, name, activated, context) {
119130 }
120131
121132 let domain = await Domain . findOne ( { ...args } ) . lean ( ) . exec ( ) ;
122- if ( activated !== undefined && domain ?. activated [ context . environment || EnvType . DEFAULT ] !== activated ) {
133+ if ( activated !== undefined && ! isElementActive ( domain , context . environment , activated ) ) {
123134 return null ;
124135 }
125136
@@ -135,6 +146,18 @@ export async function resolveDomain(_id, name, activated, context) {
135146 return domain ;
136147}
137148
149+ /**
150+ * Elemeents (Domain, Group, Config) can be activated in different environments.
151+ * When the environment is not defined, the default environment activated flag is used.
152+ */
153+ function isElementActive ( element , environment , activated ) {
154+ if ( element ?. activated [ environment || EnvType . DEFAULT ] === undefined ) {
155+ return element ?. activated [ EnvType . DEFAULT ] === activated ;
156+ }
157+
158+ return element ?. activated [ environment || EnvType . DEFAULT ] === activated ;
159+ }
160+
138161/**
139162 * Resolve components first is used by SDKs to filter only configurations in which the component
140163 * exists resulting in a snapshot size reduction.
0 commit comments