Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multi language bundled queries #192

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async function graphqlHandler(event, graphQLOptions) {
//console.log(`Skipping cache in ${ENVIRONMENT} environment`);
}

const context = { data: dataAPI, util: graphqlUtil, requestId, warnings: [] };
const context = { data: dataAPI, util: graphqlUtil, requestId, lang: {}, warnings: [] };
let result = await graphql(await getSchema(dataAPI, requestId), query, {}, context, variables);
if (context.warnings.length > 0) {
if (!result.warnings) {
Expand Down
14 changes: 8 additions & 6 deletions utils/graphql-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ module.exports = {
if (depth > depthLimit) throw new Error(`Query depth ${depth} exceeds maximum (${depthLimit}) for ${info.parentType}.${info.fieldName}.`);
},
getLang: (info, context) => {
if (context && context.lang) {
return context.lang;
}
let lang = 'en';
let langFound = false;
let myRoot = info.path.key;
Expand All @@ -24,10 +21,15 @@ module.exports = {
}
for (const selection of info.operation.selectionSet.selections) {
let selectionRoot = selection.name.value;
if (selection.alias)
if (selection.alias) {
selectionRoot = selection.alias.value;
if (selectionRoot !== myRoot)
}
if (selectionRoot !== myRoot) {
continue;
}
if (context && context.lang[myRoot]) {
return context.lang[myRoot];
}
for (const arg of selection.arguments) {
if (arg.name.value === 'lang') {
lang = arg.value.value;
Expand All @@ -38,7 +40,7 @@ module.exports = {
if (langFound) break;
}
if (context) {
context.lang = lang;
context.lang[myRoot] = lang;
}
return lang;
},
Expand Down