Skip to content

Commit

Permalink
Merge pull request usebruno#807 from vaugenwake/feature/import-graphq…
Browse files Browse the repository at this point in the history
…l-collection

feat: Adding ability to import postman graphql collections
  • Loading branch information
helloanoop authored Oct 29, 2023
2 parents 7ac39bc + 99b25fc commit fa8ec42
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/bruno-app/src/utils/importers/postman-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@ const readFile = (files) => {
});
};

const parseGraphQLRequest = (graphqlSource) => {
try {
let queryResultObject = {
query: '',
variables: ''
};

if (typeof graphqlSource === 'string') {
graphqlSource = JSON.parse(text);
}

if (graphqlSource.hasOwnProperty('variables') && graphqlSource.variables !== '') {
queryResultObject.variables = graphqlSource.variables;
}

if (graphqlSource.hasOwnProperty('query') && graphqlSource.query !== '') {
queryResultObject.query = graphqlSource.query;
}

return queryResultObject;
} catch (e) {
return {
query: '',
variables: ''
};
}
};

const isItemAFolder = (item) => {
return !item.request;
};
Expand Down Expand Up @@ -146,6 +174,12 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => {
}
}

if (bodyMode === 'graphql') {
brunoRequestItem.type = 'graphql-request';
brunoRequestItem.request.body.mode = 'graphql';
brunoRequestItem.request.body.graphql = parseGraphQLRequest(i.request.body.graphql);
}

each(i.request.header, (header) => {
brunoRequestItem.request.headers.push({
uid: uuid(),
Expand Down

0 comments on commit fa8ec42

Please sign in to comment.