Skip to content

Commit

Permalink
Merge pull request #14 from willianveiga/feature/add-output-directory…
Browse files Browse the repository at this point in the history
…-argument

Add outputDirectory argument
  • Loading branch information
alichherawalla authored Aug 26, 2024
2 parents 2db37da + d11d6aa commit 29fc6f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ graphql-testkit \
- ### maxDepth (optional)
The maximum you want to nest the generated queries and mutations. Default value is 4

- ### outputDirectory (optional)
The directory where the output is saved. Default value is "./output"

## Output
An output directory is created in the current working directory.
An output directory is created in the `outputDirectory` directory.
A folder structure based on endpoint will be created, which will contain the Postman collection(collections.json)


Expand All @@ -48,7 +51,7 @@ endpoint=https://api.spacex.land/graphql

<b>Output Directory</b>
```
output/api.spacex.land/graphql/collections.json
${outputDirectory}/api.spacex.land/graphql/collections.json
```

## License
Expand Down
4 changes: 2 additions & 2 deletions bin/graphql-testkit.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ if (!commandLineArgs[0]) {
const config = createConfig(
{
maxDepth: 4,
header: ''
header: '',
outputDirectory: `${process.cwd()}/output`
},
commandLineArgs
);
Expand Down
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function generateOperationOutput(schema, list, operationName, config) {
const entity = recursivelyHandleOfType(e);
if (!INVALID_TYPES.includes(entity.type.kind)) {
const entityObj = schema.types.find(t => t.name === entity.type.name);
shell.exec(`mkdir -p output/${config.strippedEndpoint}/${operationName}/${entity.name}`);
shell.exec(`mkdir -p ${config.outputDirectory}/${config.strippedEndpoint}/${operationName}/${entity.name}`);
let [result, variables, variablesJSON] = await createArgsAndBody(
schema,
entity,
Expand Down Expand Up @@ -183,7 +183,9 @@ async function generateOperationOutput(schema, list, operationName, config) {
request.name = `${operationName} ${entity.name}`;
await new Promise(resolve => {
fs.writeFile(
`output/${config.strippedEndpoint}/${operationName}/${entity.name}/${entity.type.name}.graphql`,
`${config.outputDirectory}/${config.strippedEndpoint}/${operationName}/${entity.name}/${
entity.type.name
}.graphql`,
result,

{ encoding: 'utf-8' },
Expand All @@ -194,7 +196,7 @@ async function generateOperationOutput(schema, list, operationName, config) {
});
await new Promise(resolve => {
fs.writeFile(
`output/${config.strippedEndpoint}/${operationName}/${entity.name}/variables.json`,
`${config.outputDirectory}/${config.strippedEndpoint}/${operationName}/${entity.name}/variables.json`,
JSON.stringify(variablesJSON),
{ encoding: 'utf-8' },
() => {
Expand Down Expand Up @@ -244,7 +246,7 @@ export const generateOutput = async config => {

// delete old output if any
await new Promise(resolve =>
shell.exec(`rm -rf output/${config.strippedEndpoint}`, { async: true }, () => resolve())
shell.exec(`rm -rf ${config.outputDirectory}/${config.strippedEndpoint}`, { async: true }, () => resolve())
);

// get all queries
Expand Down Expand Up @@ -273,7 +275,7 @@ export const generateOutput = async config => {
// write the newly created collection to the output folder
await new Promise(resolve =>
fs.writeFile(
`output/${config.strippedEndpoint}/collections.json`,
`${config.outputDirectory}/${config.strippedEndpoint}/collections.json`,
JSON.stringify(collection),
{
encoding: 'utf-8'
Expand All @@ -284,5 +286,5 @@ export const generateOutput = async config => {
)
);
spinner.succeed('Postman collection generated');
spinner.succeed(`Output written to: ${process.cwd()}/output/${config.strippedEndpoint}`);
spinner.succeed(`Output written to: ${config.outputDirectory}/${config.strippedEndpoint}`);
};

0 comments on commit 29fc6f1

Please sign in to comment.