-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST For query and mutation input and output validation
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { isPOJO } = require('../objManip'); | ||
|
||
function traverseType (type) { | ||
const types = []; | ||
function _wrapper (ast) { | ||
if (ast !== undefined) { | ||
const { type, kind, name } = ast; | ||
if (kind !== 'NamedType') types.push(_wrapper(type)); | ||
return { type, kind, name }; | ||
} else return undefined; | ||
} | ||
types.push(_wrapper(type)); | ||
return types; | ||
} | ||
|
||
function convertToString (args) { | ||
const name = args[0].name.value; | ||
let res = name; | ||
for (let i = 1; i < args.length; i++) { | ||
const arg = args[i]; | ||
if (arg.kind === 'NonNullType') res = `${res}!`; | ||
else if (arg.kind === 'ListType') res = `[${res}]`; | ||
} | ||
return res; | ||
} | ||
|
||
module.exports = { | ||
argumentsToString (argAst) { | ||
const args = []; | ||
if (argAst) | ||
argAst.forEach((arg) => { | ||
let name = arg.name.value; | ||
name = isPOJO(name) ? name.name : name; | ||
const argStr = convertToString(traverseType(arg.type)); | ||
args.push(`${name}:${argStr}`); | ||
}); | ||
return args.join(','); | ||
}, | ||
outputToString (outputAst) { | ||
return convertToString(traverseType(outputAst)); | ||
} | ||
}; |