Skip to content

Commit

Permalink
Merge branch '1.13' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 28, 2023
2 parents 14ee62c + e0f8234 commit 683fa7c
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 329 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions client/src/components/ActionMenu/ActionMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
}
}

a {
&.dropdown-item {
color: $dropdown-color;

&:active {
color: $white;
}
}
}

.dropdown-item[class*="font-icon-"]::before {
position: relative;
margin-right: $btn-icon-spacing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getQueryType = ({ queryType }) => queryType;

const buildReadQuery = (tag = defaultTag) => (
tag`${getQueryType} ${getOperationName}${getVariables} {
${getQueryName}${getParams} {
${getQueryName}(${getParams}) {
${getFields}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { defaultTag } from './tags';
import { getSingularName, getFields, getFragments, getMutationParams, getMutationVariables } from './helpers';
import { getSingularName, getFields, getFragments } from './helpers';

const buildCreateMutation = (tag = defaultTag) => (
tag`mutation Create${getSingularName}${getMutationVariables} {
create${getSingularName}${getMutationParams} {
tag`mutation Create${getSingularName}(
$Input:${getSingularName}CreateInputType!
) {
create${getSingularName}(
Input: $Input
) {
${getFields}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultTag } from './tags';
import { getSingularName, getIdOnlyVariables, getIdOnlyParams } from './helpers';
import { getSingularName } from './helpers';

const buildDeleteMutation = (tag = defaultTag) => (
tag`mutation Delete${getSingularName}${getIdOnlyVariables} {
delete${getSingularName}${getIdOnlyParams}
tag`mutation Delete${getSingularName}($IDs:[ID]!) {
delete${getSingularName}(IDs: $IDs)
}`
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultTag } from './tags';
import { getSingularName, getIdOnlyVariables, getFields, getFragments, getIdOnlyParams } from './helpers';
import { getSingularName, getFields, getFragments } from './helpers';

const buildReadOneQuery = (tag = defaultTag) => (
tag`query ReadOne${getSingularName}${getIdOnlyVariables} {
readOne${getSingularName}${getIdOnlyParams} {
tag`query ReadOne${getSingularName}($ID: ID!) {
readOne${getSingularName}(ID: $ID) {
${getFields}
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib/dependency-injection/graphql/buildReadQuery.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultTag } from './tags';
import { getPluralName, getVariables, getParams, getFields, getFragments } from './helpers';
import { getPluralName, getVariables, getRootParams, getFields, getFragments } from './helpers';

const buildReadQuery = (tag = defaultTag) => (
tag`query Read${getPluralName}${getVariables} {
read${getPluralName}${getParams} {
read${getPluralName}${getRootParams} {
${getFields}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { defaultTag } from './tags';
import { getSingularName, getMutationVariables, getMutationParams, getFields, getFragments } from './helpers';
import { getSingularName, getVariables, getParams, getFields, getFragments } from './helpers';

const buildUpdateMutation = (tag = defaultTag) => (
tag`mutation Update${getSingularName}${getMutationVariables} {
update${getSingularName}${getMutationParams} {
tag`mutation Update${getSingularName}(
$Input:${getSingularName}UpdateInputType!
${getVariables}
) {
update${getSingularName}(
Input: $Input
${getParams}
) {
${getFields}
}
}
Expand Down
139 changes: 10 additions & 129 deletions client/src/lib/dependency-injection/graphql/helpers.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { CREATE, DELETE, READ_ONE, UPDATE } from './templates';

export const ROOT_FIELD = 'root';

// used to help generate the parameters and variables
const paginationFields = {
limit: 'Int',
offset: 'Int',
};

// just outright is the parameters
const paginationParams = {
limit: 'limit',
offset: 'offset',
};

const paginateFields = (fields) => (
`edges { node { ${fields.join(' ')} } } pageInfo { totalCount }`
);
Expand All @@ -35,14 +26,20 @@ export const getVariables = ({ params, pagination = true }) => {

export const getParams = ({ params, pagination = true }) => {
const items = (pagination) ? { ...params, ...paginationFields } : params;
const paramList = Object.keys(items)
.map((paramName) => (
`${paramName}: $${paramName}`
const paramList = Object.entries(items)
.map(([paramName, varName]) => (
`${paramName}: $${varName}`
));

return paramList.length ? `(${paramList.join(', ')})` : '';
};

export const getRootParams = ({ args, pagination = true }) => {
const fieldParams = args[ROOT_FIELD] || {};

return getParams({ params: fieldParams, pagination });
};

export const getFields = ({ args, fields, pagination = true }, stack = [ROOT_FIELD]) => {
const strings = fields.map((field, i) => {
if (Array.isArray(field)) {
Expand All @@ -58,14 +55,7 @@ export const getFields = ({ args, fields, pagination = true }, stack = [ROOT_FIE
const key = path.join('/');
const fieldParams = args[key] || {};

const items = (pagination) ? { ...fieldParams, ...paginationParams } : fieldParams;
const paramList = Object.entries(items)
.map(([paramName, varName]) => (
`${paramName}: $${varName}`
));
const paramOutput = paramList.length ? `(${paramList.join(', ')})` : '';

const str = `${field}${paramOutput}`;
const str = `${field}${getParams({ params: fieldParams, pagination: false })}`;

return str;
});
Expand All @@ -86,112 +76,3 @@ export const getFragments = ({ availableFragments, fragments = [] }) => (
: capturedFragments
), '')
);

function getMatchingParamKey(matchWith, params) {
return Object.keys(params).find((paramName) => paramName.toLowerCase() === matchWith);
}

function getInputVariable({ templateName, singularName, params }) {
const inputKey = getMatchingParamKey('input', params);
if (inputKey) {
return `$${inputKey}: ${params[inputKey]}`;
}
// Graphql v3 fallbacks
switch (templateName) {
case CREATE:
return `$Input: ${getSingularName({ singularName })}CreateInputType!`;
case UPDATE:
return `$Input: ${getSingularName({ singularName })}UpdateInputType!`;
default:
throw new Error('Template is not a mutation - no input variable is required.');
}
}

function normaliseMutationParamsAndVars(paramsOrVars, dedup) {
return paramsOrVars.replace(dedup, '').replace(/(^\(+|\)+$)/mg, '');
}

export function getMutationVariables(obj) {
const inputVar = getInputVariable(obj);
switch (obj.templateName) {
case CREATE:
return `(${inputVar})`;
case UPDATE:
return `(
${inputVar}
${normaliseMutationParamsAndVars(getVariables(obj), inputVar)}
)`;
default:
throw new Error('Template is not a mutation - use getVariables() instead.');
}
}

export function getMutationParams(obj) {
const { templateName, params } = obj;
let inputKey = getMatchingParamKey('input', params);
if (!inputKey) {
// Graphql v3 fallback
inputKey = 'Input';
}
const inputParam = `${inputKey}: $${inputKey}`;

switch (templateName) {
case CREATE:
return `(${inputParam})`;
case UPDATE:
return `(
${inputParam}
${normaliseMutationParamsAndVars(getParams(obj), inputParam)}
)`;
default:
throw new Error('Template is not a mutation - use getParams() instead.');
}
}

export function getIdOnlyVariables({ templateName, params }) {
let key;
switch (templateName) {
case DELETE:
// Let developer declare casing (e.g. "Ids" or "ids")
key = getMatchingParamKey('ids', params);
if (key) {
return `($${key}: ${params[key]})`;
}
// Graphql v3 fallback
return '($IDs:[ID]!)';
case READ_ONE:
// Let developer declare casing (e.g. "Id" or "id")
key = getMatchingParamKey('id', params);
if (key) {
return `($${key}: ${params[key]})`;
}
// Graphql v3 fallback
return '($ID: ID!)';
default:
throw new Error('Unexpected template type.');
}
}

export function getIdOnlyParams({ templateName, params }) {
let key;
switch (templateName) {
case DELETE:
// Let developer declare casing (e.g. "Ids" or "ids")
key = getMatchingParamKey('ids', params);
if (key) {
return `(${key}: $${key})`;
}
// Graphql v3 fallback
return '(IDs: $IDs)';
case READ_ONE:
// Let developer declare casing (e.g. "Id" or "id")
key = getMatchingParamKey('id', params);
if (key) {
return `(${key}: $${key})`;
}
// Graphql v3 fallback
return '(ID: $ID)';
default:
throw new Error('Unexpected template type.');
}
}
7 changes: 6 additions & 1 deletion client/src/lib/dependency-injection/injectGraphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ const injectGraphql = (key, context) => (DataHandler) => {
const apolloHOC = graphqlContainer.getApolloHOC();
target = apolloHOC(DataHandler);
error = false;
} finally {
} catch (e) {
this.setState({ target, error });

// re-throw the error, as we do not want to silence it in the console
throw e;
}

this.setState({ target, error });
});
}

Expand Down
Loading

0 comments on commit 683fa7c

Please sign in to comment.