Skip to content

Commit e536b15

Browse files
authored
Merge pull request #60 from postmanlabs/release/v0.1.1
Release version v0.1.1
2 parents ca7c2a4 + 7cd63b0 commit e536b15

File tree

10 files changed

+285
-35
lines changed

10 files changed

+285
-35
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Draft new release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: The version you want to release. Must be a valid semver version.
8+
required: true
9+
type: string
10+
11+
jobs:
12+
draft-new-release:
13+
if: startsWith(github.event.inputs.version, 'v')
14+
name: Draft a new release
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
24+
- name: Create release branch
25+
run: git checkout -b release/${{ github.event.inputs.version }}
26+
27+
- name: Update changelog
28+
uses: thomaseizinger/[email protected]
29+
with:
30+
version: ${{ github.event.inputs.version }}
31+
32+
- name: Initialize mandatory git config
33+
run: |
34+
git config user.name "GitHub Actions"
35+
git config user.email [email protected]
36+
37+
- name: Bump version
38+
run: npm version ${{ github.event.inputs.version }} --git-tag-version false
39+
40+
- name: Commit changelog and manifest files
41+
id: make-commit
42+
run: |
43+
git add CHANGELOG.md package.json package-lock.json
44+
git commit --message "Prepare release ${{ github.event.inputs.version }}"
45+
echo "::set-output name=commit::$(git rev-parse HEAD)"
46+
47+
- name: Push new branch
48+
run: git push origin release/${{ github.event.inputs.version }}
49+
50+
- name: Create pull request for master
51+
uses: thomaseizinger/[email protected]
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
head: release/${{ github.event.inputs.version }}
56+
base: master
57+
title: "Release version ${{ github.event.inputs.version }}"
58+
reviewers: ${{ github.actor }}
59+
body: |
60+
Hi @${{ github.actor }}!
61+
62+
This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.
63+
I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.
64+
65+
- name: Create pull request for develop
66+
uses: thomaseizinger/[email protected]
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
with:
70+
head: release/${{ github.event.inputs.version }}
71+
base: develop
72+
title: "Release version ${{ github.event.inputs.version }}"
73+
reviewers: ${{ github.actor }}
74+
body: |
75+
Hi @${{ github.actor }}!
76+
77+
This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.
78+
I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Publish new release"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
types:
8+
- closed
9+
10+
jobs:
11+
release:
12+
name: Publish new release
13+
runs-on: ubuntu-latest
14+
# only merged pull requests that begin with 'release/' or 'hotfix/' must trigger this job
15+
if: github.event.pull_request.merged == true &&
16+
(contains(github.event.pull_request.head.ref, 'release/') || contains(github.event.pull_request.head.ref, 'hotfix/'))
17+
permissions:
18+
contents: write
19+
20+
steps:
21+
- name: Extract version from branch name (for release branches)
22+
if: contains(github.event.pull_request.head.ref, 'release/')
23+
run: |
24+
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
25+
VERSION=${BRANCH_NAME#release/}
26+
27+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
28+
29+
- name: Extract version from branch name (for hotfix branches)
30+
if: contains(github.event.pull_request.head.ref, 'hotfix/')
31+
run: |
32+
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
33+
VERSION=${BRANCH_NAME#hotfix/}
34+
35+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
36+
37+
- name: Create Release
38+
uses: thomaseizinger/[email protected]
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
with:
42+
target_commitish: ${{ github.event.pull_request.merge_commit_sha }}
43+
tag_name: ${{ env.RELEASE_VERSION }}
44+
name: ${{ env.RELEASE_VERSION }}
45+
draft: false
46+
prerelease: false

.github/workflows/test.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
name: Tests
1+
name: Test
22

33
on:
4-
[pull_request]
4+
push:
5+
branches: [develop, master]
6+
pull_request:
57

68
jobs:
79
Unit-Tests:
810
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [16.x, 18.x]
914
steps:
10-
- uses: actions/checkout@v2
11-
- uses: actions/setup-node@v1
15+
- uses: actions/checkout@v3
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v3
1218
with:
13-
node-version: '14.x'
19+
node-version: ${{ matrix.node-version }}
1420
- run: npm ci
15-
- run: npm run test
21+
- run: npm run test-lint
22+
- run: npm run test-unit

CHANGELOG.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,73 @@
11
# Changelog for graphql-to-postman
22

3+
## [Unreleased]
4+
5+
## [v0.1.1] - 2024-04-05
6+
7+
### Fixed
8+
9+
- Fixed an issue where GQL definition of having Union self refs past depth limit was failing with RangeError.
10+
311
#### v0.1.0 (June 06, 2023)
4-
* Added support for CLI usage to convert GraphQL definition to collection with custom depth.
5-
* Added maximum limit to depth allowed via usage of module APIs.
12+
13+
- Added support for CLI usage to convert GraphQL definition to collection with custom depth.
14+
- Added maximum limit to depth allowed via usage of module APIs.
615

716
### v0.0.12 (March 30, 2023)
8-
* Fixed issue where conversion failed with type error while resolving non-defined variables.
9-
* Added support for release script.
17+
18+
- Fixed issue where conversion failed with type error while resolving non-defined variables.
19+
- Added support for release script.
1020

1121
### v0.0.12 (January 9, 2023)
12-
* Fix for - [#10070](hhttps://github.com/postmanlabs/postman-app-support/issues/10070) Added support for nested lists.
22+
23+
- Fix for - [#10070](hhttps://github.com/postmanlabs/postman-app-support/issues/10070) Added support for nested lists.
1324

1425
### v0.0.11 (Sept 27, 2021)
15-
* Fix for - [#24](https://github.com/postmanlabs/graphql-to-postman/issues/24) Fixed an issue where nesting was faulty.
26+
27+
- Fix for - [#24](https://github.com/postmanlabs/graphql-to-postman/issues/24) Fixed an issue where nesting was faulty.
1628

1729
### v0.0.10 (Sept 27, 2021)
18-
* Fix for - [#9884](https://github.com/postmanlabs/postman-app-support/issues/9884) Fixed an issue with union types self referencing
30+
31+
- Fix for - [#9884](https://github.com/postmanlabs/postman-app-support/issues/9884) Fixed an issue with union types self referencing
1932

2033
### v0.0.9 (April 9, 2021)
21-
* Added the support for changing stack depth if required.
34+
35+
- Added the support for changing stack depth if required.
2236

2337
### v0.0.8 (March 15, 2021)
24-
* Fixed issue where error shown was meaningless for incorrect GraphQL SDL.
38+
39+
- Fixed issue where error shown was meaningless for incorrect GraphQL SDL.
2540

2641
### v0.0.7 (Oct 23, 2020)
27-
* fix for - [#8863](https://github.com/postmanlabs/postman-app-support/issues/8863) Fixed an issue where custom name for type threw an error.
42+
43+
- fix for - [#8863](https://github.com/postmanlabs/postman-app-support/issues/8863) Fixed an issue where custom name for type threw an error.
2844

2945
### v0.0.6 (Jul 23, 2020)
30-
* Fix for circular reference input object types.
31-
* Fix for introspection query response type support.
46+
47+
- Fix for circular reference input object types.
48+
- Fix for introspection query response type support.
3249

3350
### v0.0.5 (May 15, 2020)
34-
* Fix for - [#8429](https://github.com/postmanlabs/postman-app-support/issues/8429) [#10](https://github.com/postmanlabs/graphql-to-postman/issues/10) - Schemas with Input type will now be converted successfully.
51+
52+
- Fix for - [#8429](https://github.com/postmanlabs/postman-app-support/issues/8429) [#10](https://github.com/postmanlabs/graphql-to-postman/issues/10) - Schemas with Input type will now be converted successfully.
3553

3654
#### v0.0.4 (April 29, 2020)
37-
* Sanitization of options.
38-
* Added a function for getting meta data.
55+
56+
- Sanitization of options.
57+
- Added a function for getting meta data.
3958

4059
#### v0.0.3 (March 26, 2020)
41-
* Fix for empty collection generation for certain queries.
60+
61+
- Fix for empty collection generation for certain queries.
4262

4363
#### v0.0.2 (December 20, 2019)
44-
* Support for GraphQL variables.
64+
65+
- Support for GraphQL variables.
4566

4667
#### v0.0.1 (December 10, 2019)
47-
* Base release
68+
69+
- Base release
70+
71+
[Unreleased]: https://github.com/postmanlabs/graphql-to-postman/compare/v0.1.1...HEAD
72+
73+
[v0.1.1]: https://github.com/postmanlabs/graphql-to-postman/compare/011f91a2fff94f02aeefcfc004a96777a62829bb...v0.1.1

lib/assets/gql-generator.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ var graphql = require('graphql'),
1818
* @param dict dictionary of arguments
1919
*/
2020
getArgsToVarsStr = (dict) => {
21+
if (typeof dict !== 'object') {
22+
return '';
23+
}
24+
2125
return Object.entries(dict)
2226
.map(([varName, arg]) => { return `${arg.name}: $${varName}`; })
2327
.join(', ');
@@ -102,6 +106,10 @@ var graphql = require('graphql'),
102106
* @param dict dictionary of arguments
103107
*/
104108
getVarsToTypesStr = (dict) => {
109+
if (typeof dict !== 'object') {
110+
return '';
111+
}
112+
105113
return Object.entries(dict)
106114
.map(([varName, arg]) => {
107115
return `$${varName}: ${arg.type}`;
@@ -151,7 +159,7 @@ function resolveVariableType (type, gqlSchema, stack = 0, stackLimit = 4) {
151159

152160
if (graphql.isInputObjectType(argType)) {
153161
fields = argType.getFields();
154-
Object.keys(fields).forEach((field) => {
162+
typeof fields === 'object' && Object.keys(fields).forEach((field) => {
155163
if (fields[field].type === type) {
156164
fieldObj[field] = '<Same as ' + type + '>';
157165
}
@@ -241,7 +249,7 @@ module.exports = {
241249
}
242250
crossReferenceKeyList[crossReferenceKey] = true;
243251

244-
let childKeys = Object.keys(curType.getFields());
252+
let childKeys = Object.keys(curType.getFields() || {});
245253
childQuery = childKeys
246254
.filter((fieldName) => {
247255
/* Exclude deprecated fields */
@@ -273,6 +281,16 @@ module.exports = {
273281

274282
/* Union types */
275283
if (curType.astNode && curType.astNode.kind === 'UnionTypeDefinition') {
284+
285+
/* Make sure UnionTypeDefinition are also not circularly referenced */
286+
if ((crossReferenceKeyList.hasOwnProperty(crossReferenceKey) && crossReferenceKeyList[crossReferenceKey]) ||
287+
curDepth > depthLimit
288+
) {
289+
crossReferenceKeyList[crossReferenceKey] = false;
290+
return '';
291+
}
292+
crossReferenceKeyList[crossReferenceKey] = true;
293+
276294
const types = curType.getTypes();
277295
if (types && types.length) {
278296
const indent = `${' '.repeat(curDepth)}`,
@@ -282,7 +300,7 @@ module.exports = {
282300
for (let i = 0, len = types.length; i < len; i++) {
283301
const valueTypeName = types[i],
284302
valueType = gqlSchema.getType(valueTypeName),
285-
unionChildQuery = Object.keys(valueType.getFields())
303+
unionChildQuery = Object.keys(valueType.getFields() || {})
286304
.map((cur) => {
287305
// Don't genrate query fields that have self referencing
288306
if (cur === curName) {
@@ -330,7 +348,7 @@ module.exports = {
330348
console.log('[gqlg warning]:', 'description is required');
331349
}
332350

333-
Object.keys(obj).forEach((type) => {
351+
typeof obj === 'object' && Object.keys(obj).forEach((type) => {
334352

335353
let field,
336354
newDescription;
@@ -358,9 +376,12 @@ module.exports = {
358376

359377
/* Generate variables Object from argumentDict */
360378
var variables = {};
361-
Object.entries(queryResult.argumentsDict).map(([varName, arg]) => {
362-
variables[varName] = resolveVariableType(arg.type, gqlSchema, 0, stackLimit);
363-
});
379+
380+
if (typeof queryResult.argumentsDict === 'object') {
381+
Object.entries(queryResult.argumentsDict).map(([varName, arg]) => {
382+
variables[varName] = resolveVariableType(arg.type, gqlSchema, 0, stackLimit);
383+
});
384+
}
364385

365386
let query = queryResult.queryStr;
366387
// here the `description` is used to construct the actual queries

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-to-postman",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Generates a Postman Collection from a GraphQL schema.",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)