Skip to content

Commit

Permalink
Merge pull request #15 from wednesday-solutions/fix/empty-root-minus1…
Browse files Browse the repository at this point in the history
…-operations

feat: ignore attempt to create operation folder if there are no operations of type
  • Loading branch information
alichherawalla authored Aug 26, 2024
2 parents c20e85d + 0930006 commit a39fdb6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bin/graphql-testkit.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (!commandLineArgs[0]) {
'\nendpoint=GraphQL endpoint you want to create the postman collection for\n' +
'headers=Comma separated list of headers that you want to pass with the request to get the schema\n' +
'maxDepth=Maximum amount of nesting you want in the auto-generated queries and mutations\n' +
'outputDirectory=Output directory to store the schema and collection in\n' +
''
);
} else {
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import { v4 } from 'uuid';
import { cloneDeep } from 'lodash';
import { cloneDeep, isEmpty } from 'lodash';
import baseCollection from './base-collection.json';
import sampleFolder from './base-folder.json';
import sampleRequest from './base-request.json';
Expand Down Expand Up @@ -142,6 +142,10 @@ async function createArgsAndBody(
}

async function generateOperationOutput(schema, list, operationName, config) {
if (isEmpty(list)) {
// there are no operations of type ${operationName}
return;
}
// create a new folder for queries/mutations/subscriptions
const folder = cloneDeep(sampleFolder);
folder.name = operationName;
Expand Down Expand Up @@ -211,7 +215,7 @@ async function generateOperationOutput(schema, list, operationName, config) {
}

export const generateOutput = async config => {
config.strippedEndpoint = config.endpoint.replace(/(http|https):\/\//, '');
config.strippedEndpoint = config.endpoint.replace(/(http|https):\/\//, '').replaceAll('.', '_');

// create collection
const collection = {};
Expand Down Expand Up @@ -250,9 +254,9 @@ export const generateOutput = async config => {
);

// get all queries
const queries = schema.types.find(t => t.name === 'Query').fields;
const queries = schema.types.find(t => t.name === 'Query')?.fields;
// get all mutations
const mutations = schema.types.find(t => t.name === 'Mutation').fields;
const mutations = schema.types.find(t => t.name === 'Mutation')?.fields;

const createCollection = async () => {
spinner.stop();
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ module.exports = {
],
resolve: {
modules: ['node_modules', 'app'],
mainFields: ['browser', 'jsnext:main', 'main']
mainFields: ['jsnext:main', 'main']
}
};

0 comments on commit a39fdb6

Please sign in to comment.