Skip to content

Commit

Permalink
Mapped scalar types are now used as input and output instead of havin…
Browse files Browse the repository at this point in the history
…g to be an input/output object
  • Loading branch information
eddeee888 committed May 16, 2023
1 parent d9436a7 commit 2665abf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
25 changes: 7 additions & 18 deletions packages/plugins/other/visitor-plugin-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,30 +325,19 @@ export function buildScalars(
outputMapper.type += "['output']";
}

result[name] = {
input: inputMapper,
output: outputMapper,
};
} else if (scalarsMapping && typeof scalarsMapping[name] === 'string') {
const normalizedScalar = normalizeScalarType(scalarsMapping[name]);

const inputMapper = parseMapper(normalizedScalar.input, name);
if (inputMapper.isExternal) {
inputMapper.type += "['input']";
}

const outputMapper = parseMapper(normalizedScalar.output, name);
if (outputMapper.isExternal) {
outputMapper.type += "['output']";
}

result[name] = {
input: inputMapper,
output: outputMapper,
};
} else if (scalarsMapping?.[name]) {
const mappedScalar = scalarsMapping[name];
if (typeof mappedScalar === 'object' && mappedScalar.input && mappedScalar.output) {
if (typeof mappedScalar === 'string') {
const normalizedScalar = normalizeScalarType(scalarsMapping[name]);
result[name] = {
input: parseMapper(normalizedScalar.input, name),
output: parseMapper(normalizedScalar.output, name),
};
} else if (typeof mappedScalar === 'object' && mappedScalar.input && mappedScalar.output) {
result[name] = {
input: parseMapper(mappedScalar.input, name),
output: parseMapper(mappedScalar.output, name),
Expand Down
12 changes: 6 additions & 6 deletions packages/plugins/typescript/typescript/tests/typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2006,12 +2006,12 @@ describe('TypeScript', () => {
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
MyScalar: { input: MyScalar['input']; output: MyScalar['output']; }
MyOtherScalar: { input: MyOtherScalar['input']; output: MyOtherScalar['output']; }
MyAliasedScalar: { input: AliasedScalar['input']; output: AliasedScalar['output']; }
OrgScalar: { input: OrgScalar['input']; output: OrgScalar['output']; }
OrgOtherScalar: { input: OrgOtherScalar['input']; output: OrgOtherScalar['output']; }
OrgAliasedScalar: { input: OrgAliasedScalar['input']; output: OrgAliasedScalar['output']; }
MyScalar: { input: MyScalar; output: MyScalar; }
MyOtherScalar: { input: MyOtherScalar; output: MyOtherScalar; }
MyAliasedScalar: { input: AliasedScalar; output: AliasedScalar; }
OrgScalar: { input: OrgScalar; output: OrgScalar; }
OrgOtherScalar: { input: OrgOtherScalar; output: OrgOtherScalar; }
OrgAliasedScalar: { input: OrgAliasedScalar; output: OrgAliasedScalar; }
};`);

expect(result.content).toBeSimilarStringTo(`
Expand Down

0 comments on commit 2665abf

Please sign in to comment.