test: improve utils coverage (#4230)

* test: improve utils coverage

* refactor: review - rename isDefined to isNonNullable, update tests and return statement
This commit is contained in:
Thaïs
2024-02-29 13:03:52 -03:00
committed by GitHub
parent 6ec0e5e995
commit 30df6c10ea
85 changed files with 396 additions and 240 deletions

View File

@ -8,19 +8,22 @@ export const parseApolloStoreFieldName = <
>(
storeFieldName: string,
) => {
const matches = storeFieldName.match(/([a-zA-Z][a-zA-Z0-9 ]*)\((.*)\)/);
const matches = storeFieldName.match(/([a-zA-Z][a-zA-Z0-9 ]*)(\((.*)\))?/);
if (!matches?.[1]) return {};
const fieldName = matches?.[1];
const [, , stringifiedVariables] = matches;
const fieldName = matches[1] as string;
if (!fieldName) {
return {};
}
const stringifiedVariables = matches[3];
try {
const fieldArguments = stringifiedVariables
const fieldVariables = stringifiedVariables
? (JSON.parse(stringifiedVariables) as Variables)
: undefined;
return { fieldName, fieldArguments };
return { fieldName, fieldVariables };
} catch {
return { fieldName };
}