├── .eslintrc
├── .github
└── workflows
│ ├── draft-new-release.yml
│ ├── publish-new-release.yml
│ └── test.yml
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── bin
└── gql2postman.js
├── index.js
├── lib
├── assets
│ └── gql-generator.js
├── index.js
└── util.js
├── npm
├── release.sh
├── test-lint.js
├── test-unit.js
└── test.js
├── package-lock.json
├── package.json
└── test
├── .eslintrc
└── unit
├── converter.test.js
├── fixtures
├── circularInput.graphql
├── custom-queryname.gql
├── invalidNestedArgumentSchema.graphql
├── invalidSchema.json
├── invalidSchemaSDL.graphql
├── issue#10.graphql
├── seflRefDepthUnionSchema.graphql
├── selfRefUnionTypeExample.graphql
├── validNestedArgumentSchema.graphql
├── validNestedSchema.graphql
├── validSchema.json
└── validSchemaSDL.graphql
├── gql-generator.test.js
└── plugin.test.js
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "jsdoc",
4 | "security",
5 | "lodash"
6 | ],
7 | "env": {
8 | "node": true,
9 | "es6": true
10 | },
11 | "rules": {
12 | // Possible Errors
13 | "for-direction": "error",
14 | "getter-return": "error",
15 | "no-await-in-loop": "error",
16 | "no-compare-neg-zero": "error",
17 | "no-cond-assign": "error",
18 | "no-console": "off",
19 | "no-constant-condition": "error",
20 | "no-control-regex": "error",
21 | "no-debugger": "error",
22 | "no-dupe-args": "error",
23 | "no-dupe-keys": "error",
24 | "no-duplicate-case": "error",
25 | "no-empty": "error",
26 | "no-empty-character-class": "error",
27 | "no-ex-assign": "error",
28 | "no-extra-boolean-cast": "error",
29 | "no-extra-parens": "off",
30 | "no-extra-semi": "error",
31 | "no-func-assign": "error",
32 | "no-inner-declarations": "off",
33 | "no-invalid-regexp": "error",
34 | "no-irregular-whitespace": "error",
35 | "no-obj-calls": "error",
36 | "no-prototype-builtins": "off",
37 | "no-regex-spaces": "error",
38 | "no-sparse-arrays": "error",
39 | "no-template-curly-in-string": "error",
40 | "no-unexpected-multiline": "error",
41 | "no-unreachable": "error",
42 | "no-unsafe-finally": "error",
43 | "no-unsafe-negation": "error",
44 | "use-isnan": "error",
45 | "valid-jsdoc": "off",
46 | "valid-typeof": "error",
47 |
48 | // Best Practices
49 | "accessor-pairs": "error",
50 | "array-callback-return": "off",
51 | "block-scoped-var": "error",
52 | "class-methods-use-this": "error",
53 | "complexity": "off",
54 | "consistent-return": "warn",
55 | "curly": "error",
56 | "default-case": "error",
57 | "dot-location": ["error", "property"],
58 | "dot-notation": "error",
59 | "eqeqeq": "error",
60 | "guard-for-in": "warn",
61 | "no-alert": "error",
62 | "no-caller": "error",
63 | "no-case-declarations": "error",
64 | "no-div-regex": "error",
65 | "no-else-return": "error",
66 | "no-empty-function": "error",
67 | "no-empty-pattern": "error",
68 | "no-eq-null": "error",
69 | "no-eval": "error",
70 | "no-extend-native": "error",
71 | "no-extra-bind": "error",
72 | "no-extra-label": "error",
73 | "no-fallthrough": "error",
74 | "no-floating-decimal": "error",
75 | "no-global-assign": "error",
76 | "no-implicit-coercion": "error",
77 | "no-implicit-globals": "error",
78 | "no-implied-eval": "error",
79 | "no-invalid-this": "error",
80 | "no-iterator": "error",
81 | "no-labels": "error",
82 | "no-lone-blocks": "error",
83 | "no-loop-func": "error",
84 | "no-magic-numbers": "off",
85 | "no-multi-spaces": "error",
86 | "no-multi-str": "error",
87 | "no-new": "error",
88 | "no-new-func": "error",
89 | "no-new-wrappers": "error",
90 | "no-octal": "error",
91 | "no-octal-escape": "error",
92 | "no-param-reassign": "off",
93 | "no-proto": "error",
94 | "no-redeclare": "error",
95 | "no-restricted-properties": "error",
96 | "no-return-assign": "error",
97 | "no-return-await": "error",
98 | "no-script-url": "error",
99 | "no-self-assign": "error",
100 | "no-self-compare": "error",
101 | "no-sequences": "error",
102 | "no-throw-literal": "error",
103 | "no-unmodified-loop-condition": "error",
104 | "no-unused-expressions": "off",
105 | "no-unused-labels": "error",
106 | "no-useless-call": "error",
107 | "no-useless-concat": "error",
108 | "no-useless-escape": "error",
109 | "no-useless-return": "error",
110 | "no-void": "error",
111 | "no-warning-comments": "off",
112 | "no-with": "error",
113 | "prefer-promise-reject-errors": "error",
114 | "radix": "off",
115 | "require-await": "error",
116 | "vars-on-top": "off",
117 | "wrap-iife": "error",
118 | "yoda": "error",
119 |
120 | // Strict Mode
121 | "strict": "off",
122 |
123 | // Variables
124 | "init-declarations": "off",
125 | "no-catch-shadow": "error",
126 | "no-delete-var": "error",
127 | "no-label-var": "error",
128 | "no-restricted-globals": "error",
129 | "no-shadow": "off",
130 | "no-shadow-restricted-names": "error",
131 | "no-undef": "off",
132 | "no-undef-init": "error",
133 | "no-undefined": "off",
134 | "no-unused-vars": "error",
135 | "no-use-before-define": "error",
136 |
137 | // Node.js and CommonJS
138 | "callback-return": "error",
139 | "global-require": "off",
140 | "handle-callback-err": "error",
141 | "no-buffer-constructor": "error",
142 | "no-mixed-requires": "off",
143 | "no-new-require": "off",
144 | "no-path-concat": "error",
145 | "no-process-env": "error",
146 | "no-process-exit": "off",
147 | "no-restricted-modules": "error",
148 | "no-sync": "off",
149 |
150 | // Stylistic Issues
151 | "array-bracket-newline": "off",
152 | "array-bracket-spacing": "off",
153 | "array-element-newline": "off",
154 | "block-spacing": "error",
155 | "brace-style": [2, "stroustrup", { "allowSingleLine": true }],
156 | "camelcase": "off",
157 | "capitalized-comments": "off",
158 | "comma-dangle": ["error", "never"],
159 | "comma-spacing": [2, { "before": false, "after": true }],
160 | "comma-style": ["error", "last"],
161 | "computed-property-spacing": "error",
162 | "consistent-this": "off",
163 | "eol-last": "error",
164 | "func-call-spacing": "error",
165 | "func-name-matching": "off",
166 | "func-names": "off",
167 | "func-style": "off",
168 | "id-blacklist": "error",
169 | "id-length": "off",
170 | "id-match": "error",
171 | "indent": ["error", 2, {
172 | "VariableDeclarator": { "var": 1, "let": 1, "const": 1 },
173 | "SwitchCase": 1
174 | }],
175 | "jsx-quotes": ["error", "prefer-single"],
176 | "key-spacing": "error",
177 | "keyword-spacing": "error",
178 | "line-comment-position": "off",
179 | "linebreak-style": ["error", "unix"],
180 | "lines-around-comment": ["error", {
181 | "beforeBlockComment": true,
182 | "afterBlockComment": false,
183 | "beforeLineComment": false,
184 | "afterLineComment": false,
185 | "allowBlockStart": true,
186 | "allowBlockEnd": false,
187 | "allowObjectStart": true,
188 | "allowObjectEnd": false,
189 | "allowArrayStart": true,
190 | "allowArrayEnd": false
191 | }],
192 | "max-depth": "error",
193 | "max-len": ["error", {
194 | "code": 120
195 | }],
196 | "max-lines": "off",
197 | "max-nested-callbacks": "error",
198 | "max-params": "off",
199 | "max-statements": "off",
200 | "max-statements-per-line": "off",
201 | "multiline-ternary": "off",
202 | "new-cap": "off",
203 | "new-parens": "error",
204 | "newline-per-chained-call": "off",
205 | "no-array-constructor": "error",
206 | "no-bitwise": "off",
207 | "no-continue": "off",
208 | "no-inline-comments": "off",
209 | "no-lonely-if": "error",
210 | "no-mixed-operators": "off",
211 | "no-mixed-spaces-and-tabs": "error",
212 | "no-multi-assign": "off",
213 | "no-multiple-empty-lines": "error",
214 | "no-negated-condition": "off",
215 | "no-nested-ternary": "off",
216 | "no-new-object": "error",
217 | "no-plusplus": "off",
218 | "no-restricted-syntax": "error",
219 | "no-tabs": "error",
220 | "no-ternary": "off",
221 | "no-trailing-spaces": "error",
222 | "no-underscore-dangle": "off",
223 | "no-unneeded-ternary": "error",
224 | "no-whitespace-before-property": "error",
225 | "nonblock-statement-body-position": "error",
226 | "object-curly-newline": "off",
227 | "object-curly-spacing": "off",
228 | "object-property-newline": "off",
229 | "one-var": ["error", "always"],
230 | "one-var-declaration-per-line": "error",
231 | "operator-assignment": "error",
232 | "operator-linebreak": ["error", "after"],
233 | "padded-blocks": "off",
234 | "padding-line-between-statements": "off",
235 | "quote-props": "off",
236 | "quotes": ["error", "single"],
237 | "require-jsdoc": "warn",
238 | "semi": "error",
239 | "semi-spacing": "error",
240 | "sort-keys": "off",
241 | "sort-vars": "off",
242 | "space-before-blocks": "error",
243 | "space-before-function-paren": "error",
244 | "space-in-parens": "error",
245 | "space-infix-ops": "error",
246 | "space-unary-ops": "error",
247 | "spaced-comment": ["error", "always", {
248 | "block": {
249 | "exceptions": ["!"]
250 | }
251 | }],
252 | "switch-colon-spacing": "error",
253 | "template-tag-spacing": "error",
254 | "unicode-bom": "error",
255 | "wrap-regex": "error",
256 |
257 | // ECMAScript 6
258 | "arrow-body-style": ["error", "always"],
259 | "arrow-parens": ["error", "always"],
260 | "arrow-spacing": "error",
261 | "constructor-super": "error",
262 | "generator-star-spacing": "error",
263 | "no-class-assign": "error",
264 | "no-confusing-arrow": "error",
265 | "no-const-assign": "error",
266 | "no-dupe-class-members": "error",
267 | "no-duplicate-imports": "error",
268 | "no-new-symbol": "error",
269 | "no-restricted-imports": "error",
270 | "no-this-before-super": "error",
271 | "no-useless-computed-key": "error",
272 | "no-useless-constructor": "off",
273 | "no-var": "off",
274 | "object-shorthand": "off",
275 | "prefer-arrow-callback": "off",
276 | "prefer-const": "off",
277 | "prefer-destructuring": "off",
278 | "prefer-numeric-literals": "off",
279 | "prefer-rest-params": "off",
280 | "prefer-spread": "error",
281 | "prefer-template": "off",
282 | "require-yield": "error",
283 | "rest-spread-spacing": "error",
284 | "sort-imports": "off",
285 | "symbol-description": "off",
286 | "template-curly-spacing": "error",
287 | "yield-star-spacing": "error",
288 |
289 | // Lodash
290 | "lodash/callback-binding": "error",
291 | "lodash/collection-method-value": "warn",
292 | "lodash/collection-return": "error",
293 | "lodash/no-double-unwrap": "error",
294 | "lodash/no-extra-args": "error",
295 | "lodash/no-unbound-this": "error",
296 | "lodash/unwrap": "error",
297 |
298 | "lodash/chain-style": ["error", "as-needed"],
299 | "lodash/chaining": ["error", "always", 3],
300 | "lodash/consistent-compose": ["error", "flow"],
301 | "lodash/identity-shorthand": ["error", "always"],
302 | "lodash/import-scope": "off",
303 | "lodash/matches-prop-shorthand": ["error", "always"],
304 | "lodash/matches-shorthand": ["error", "always", 3],
305 | "lodash/no-commit": "error",
306 | "lodash/path-style": ["error", "as-needed"],
307 | "lodash/prefer-compact": "error",
308 | "lodash/prefer-filter": ["off", 3],
309 | "lodash/prefer-flat-map": "error",
310 | "lodash/prefer-invoke-map": "error",
311 | "lodash/prefer-map": "error",
312 | "lodash/prefer-reject": ["error", 3],
313 | "lodash/prefer-thru": "error",
314 | "lodash/prefer-wrapper-method": "error",
315 | "lodash/preferred-alias": "off",
316 | "lodash/prop-shorthand": ["error", "always"],
317 |
318 | "lodash/prefer-constant": "off",
319 | "lodash/prefer-get": ["warn", 4],
320 | "lodash/prefer-includes": ["error", { "includeNative": true }],
321 | "lodash/prefer-is-nil": "error",
322 | "lodash/prefer-lodash-chain": "error",
323 | "lodash/prefer-lodash-method": "off",
324 | "lodash/prefer-lodash-typecheck": "off",
325 | "lodash/prefer-matches": ["off", 3],
326 | "lodash/prefer-noop": "off",
327 | "lodash/prefer-over-quantifier": "warn",
328 | "lodash/prefer-some": "off",
329 | "lodash/prefer-startswith": "off",
330 | "lodash/prefer-times": "off",
331 |
332 | // JsDoc
333 | "jsdoc/check-param-names": "error",
334 | "jsdoc/check-tag-names": "off",
335 | "jsdoc/check-types": "off",
336 | "jsdoc/newline-after-description": "error",
337 | "jsdoc/require-description-complete-sentence": "off",
338 | "jsdoc/require-example": "off",
339 | "jsdoc/require-hyphen-before-param-description": "off",
340 | "jsdoc/require-param": "error",
341 | "jsdoc/require-param-description": "off",
342 | "jsdoc/require-param-type": "off",
343 | "jsdoc/require-returns-description": "off",
344 | "jsdoc/require-returns-type": "error",
345 |
346 | // Security
347 | "security/detect-unsafe-regex": "off",
348 | "security/detect-buffer-noassert": "error",
349 | "security/detect-child-process": "error",
350 | "security/detect-disable-mustache-escape": "error",
351 | "security/detect-eval-with-expression": "error",
352 | "security/detect-no-csrf-before-method-override": "off",
353 | "security/detect-non-literal-fs-filename": "off",
354 | "security/detect-non-literal-regexp": "warn",
355 | "security/detect-non-literal-require": "off",
356 | "security/detect-object-injection": "off",
357 | "security/detect-possible-timing-attacks": "error",
358 | "security/detect-pseudoRandomBytes": "error"
359 | }
360 | }
361 |
--------------------------------------------------------------------------------
/.github/workflows/draft-new-release.yml:
--------------------------------------------------------------------------------
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/keep-a-changelog-new-release@1.1.0
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 noreply@github.com
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/create-pull-request@1.0.0
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/create-pull-request@1.0.0
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 }}.
79 |
--------------------------------------------------------------------------------
/.github/workflows/publish-new-release.yml:
--------------------------------------------------------------------------------
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/create-release@1.0.0
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
47 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | branches: [develop, master]
6 | pull_request:
7 |
8 | jobs:
9 | Unit-Tests:
10 | runs-on: ubuntu-latest
11 | strategy:
12 | matrix:
13 | node-version: [18.x, 20.x, 22.x]
14 | steps:
15 | - uses: actions/checkout@v3
16 | - name: Use Node.js ${{ matrix.node-version }}
17 | uses: actions/setup-node@v3
18 | with:
19 | node-version: ${{ matrix.node-version }}
20 | - run: npm ci
21 | - run: npm run test-lint
22 | - run: npm run test-unit
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 |
9 | # Diagnostic reports (https://nodejs.org/api/report.html)
10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 |
12 | # Runtime data
13 | pids
14 | *.pid
15 | *.seed
16 | *.pid.lock
17 |
18 | # Directory for instrumented libs generated by jscoverage/JSCover
19 | lib-cov
20 |
21 | # Coverage directory used by tools like istanbul
22 | coverage
23 | *.lcov
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # TypeScript v1 declaration files
45 | typings/
46 |
47 | # TypeScript cache
48 | *.tsbuildinfo
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional eslint cache
54 | .eslintcache
55 |
56 | # Microbundle cache
57 | .rpt2_cache/
58 | .rts2_cache_cjs/
59 | .rts2_cache_es/
60 | .rts2_cache_umd/
61 |
62 | # Optional REPL history
63 | .node_repl_history
64 |
65 | # Output of 'npm pack'
66 | *.tgz
67 |
68 | # Yarn Integrity file
69 | .yarn-integrity
70 |
71 | # dotenv environment variables file
72 | .env
73 | .env.test
74 |
75 | # parcel-bundler cache (https://parceljs.org/)
76 | .cache
77 |
78 | # Next.js build output
79 | .next
80 |
81 | # Nuxt.js build / generate output
82 | .nuxt
83 | dist
84 |
85 | # Gatsby files
86 | .cache/
87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
88 | # https://nextjs.org/blog/next-9-1#public-directory-support
89 | # public
90 |
91 | # vuepress build output
92 | .vuepress/dist
93 |
94 | # Serverless directories
95 | .serverless/
96 |
97 | # FuseBox cache
98 | .fusebox/
99 |
100 | # DynamoDB Local files
101 | .dynamodb/
102 |
103 | # TernJS port file
104 | .tern-port
105 |
106 | .coverage
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | ### NPM Specific: Disregard recursive project files
2 | ### ===============================================
3 | /.editorconfig
4 | /.gitmodules
5 | /test
6 |
7 | ### Borrowed from .gitignore
8 | ### ========================
9 |
10 | # Logs
11 | logs
12 | *.log
13 | npm-debug.log*
14 | yarn-debug.log*
15 | yarn-error.log*
16 |
17 | # Runtime data
18 | pids
19 | *.pid
20 | *.seed
21 | *.pid.lock
22 |
23 | # Prevent IDE stuff
24 | .idea
25 | .vscode
26 | *.sublime-*
27 |
28 | # Directory for instrumented libs generated by jscoverage/JSCover
29 | lib-cov
30 |
31 | # Coverage directory used by tools like istanbul
32 | .coverage
33 |
34 | # nyc test coverage
35 | .nyc_output
36 |
37 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
38 | .grunt
39 |
40 | # Bower dependency directory (https://bower.io/)
41 | bower_components
42 |
43 | # node-waf configuration
44 | .lock-wscript
45 |
46 | # Compiled binary addons (http://nodejs.org/api/addons.html)
47 | build/Release
48 |
49 | # Dependency directories
50 | node_modules/
51 | jspm_packages/
52 |
53 | # Typescript v1 declaration files
54 | typings/
55 |
56 | # Optional npm cache directory
57 | .npm
58 |
59 | # Optional eslint cache
60 | .eslintcache
61 |
62 | # Optional REPL history
63 | .node_repl_history
64 |
65 | # Output of 'npm pack'
66 | *.tgz
67 |
68 | # Yarn Integrity file
69 | .yarn-integrity
70 |
71 | # dotenv environment variables file
72 | .env
73 |
74 | out/
75 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "7"
4 | - "8"
5 | - "9"
6 | - "node"
7 | - "lts/*"
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog for graphql-to-postman
2 |
3 | ## [Unreleased]
4 |
5 | ## [v1.0.0] - 2025-03-07
6 |
7 | ### Breaking Changes
8 |
9 | - Drop support for node < v18.
10 |
11 | ## [v0.3.0] - 2024-07-10
12 |
13 | ### Chore
14 |
15 | - Updated postman-collection to v4.4.0.
16 |
17 | ## [v0.2.0] - 2024-07-03
18 |
19 | ### Updated
20 |
21 | - Updated graphql version to v15.8.0.
22 |
23 | ## [v0.1.1] - 2024-04-05
24 |
25 | ### Fixed
26 |
27 | - Fixed an issue where GQL definition of having Union self refs past depth limit was failing with RangeError.
28 |
29 | #### v0.1.0 (June 06, 2023)
30 |
31 | - Added support for CLI usage to convert GraphQL definition to collection with custom depth.
32 | - Added maximum limit to depth allowed via usage of module APIs.
33 |
34 | ### v0.0.12 (March 30, 2023)
35 |
36 | - Fixed issue where conversion failed with type error while resolving non-defined variables.
37 | - Added support for release script.
38 |
39 | ### v0.0.12 (January 9, 2023)
40 |
41 | - Fix for - [#10070](hhttps://github.com/postmanlabs/postman-app-support/issues/10070) Added support for nested lists.
42 |
43 | ### v0.0.11 (Sept 27, 2021)
44 |
45 | - Fix for - [#24](https://github.com/postmanlabs/graphql-to-postman/issues/24) Fixed an issue where nesting was faulty.
46 |
47 | ### v0.0.10 (Sept 27, 2021)
48 |
49 | - Fix for - [#9884](https://github.com/postmanlabs/postman-app-support/issues/9884) Fixed an issue with union types self referencing
50 |
51 | ### v0.0.9 (April 9, 2021)
52 |
53 | - Added the support for changing stack depth if required.
54 |
55 | ### v0.0.8 (March 15, 2021)
56 |
57 | - Fixed issue where error shown was meaningless for incorrect GraphQL SDL.
58 |
59 | ### v0.0.7 (Oct 23, 2020)
60 |
61 | - fix for - [#8863](https://github.com/postmanlabs/postman-app-support/issues/8863) Fixed an issue where custom name for type threw an error.
62 |
63 | ### v0.0.6 (Jul 23, 2020)
64 |
65 | - Fix for circular reference input object types.
66 | - Fix for introspection query response type support.
67 |
68 | ### v0.0.5 (May 15, 2020)
69 |
70 | - 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.
71 |
72 | #### v0.0.4 (April 29, 2020)
73 |
74 | - Sanitization of options.
75 | - Added a function for getting meta data.
76 |
77 | #### v0.0.3 (March 26, 2020)
78 |
79 | - Fix for empty collection generation for certain queries.
80 |
81 | #### v0.0.2 (December 20, 2019)
82 |
83 | - Support for GraphQL variables.
84 |
85 | #### v0.0.1 (December 10, 2019)
86 |
87 | - Base release
88 |
89 | [Unreleased]: https://github.com/postmanlabs/graphql-to-postman/compare/v1.0.0...HEAD
90 |
91 | [v1.0.0]: https://github.com/postmanlabs/graphql-to-postman/compare/v0.3.0...v1.0.0
92 |
93 | [v0.3.0]: https://github.com/postmanlabs/graphql-to-postman/compare/v0.2.0...v0.3.0
94 |
95 | [v0.2.0]: https://github.com/postmanlabs/graphql-to-postman/compare/v0.1.1...v0.2.0
96 |
97 | [v0.1.1]: https://github.com/postmanlabs/graphql-to-postman/compare/011f91a2fff94f02aeefcfc004a96777a62829bb...v0.1.1
98 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | *Supercharge your API workflow.*
4 | *Modern software is built on APIs. Postman helps you develop APIs faster.*
5 |
6 | # GraphQL to Postman Collection
7 |
8 | 
9 |
10 | 
11 | 
12 |
13 | #### Contents
14 |
15 | 1. [Getting Started](#getting-started)
16 | 2. [Command Line Interface](#command-line-interface)
17 | 1. [Options](#options)
18 | 2. [Usage](#usage)
19 | 3. [Using the converter as a NodeJS module](#using-the-converter-as-a-nodejs-module)
20 | 1. [Convert Function](#convert)
21 | 2. [Options](#options)
22 | 3. [ConversionResult](#conversionresult)
23 | 4. [Sample usage](#sample-usage)
24 | 5. [Validate function](#validate-function)
25 | 4. [Conversion Schema](#conversion-schema)
26 |
27 | ---
28 |
29 | ---
30 |
31 |
32 | ## 💭 Getting Started
33 |
34 | To use the converter as a Node module, you need to have a copy of the NodeJS runtime. The easiest way to do this is through npm. If you have NodeJS installed you have npm installed as well.
35 |
36 | ```terminal
37 | $ npm install graphql-to-postman
38 | ```
39 |
40 | If you want to use the converter in the CLI, install it globally with NPM:
41 |
42 | ```terminal
43 | $ npm i -g graphql-to-postman
44 | ```
45 |
46 |
47 | ## 📖 Command Line Interface
48 |
49 | The converter can be used as a CLI tool as well. The following [command line options](#options) are available.
50 |
51 | `gql2postman [options]`
52 |
53 | ### Options
54 |
55 | - `-s `, `--spec `
56 | Used to specify the GraphQL specification (file path) which is to be converted
57 |
58 | - `-o `, `--output `
59 | Used to specify the destination file in which the collection is to be written
60 |
61 | - `-p`, `--pretty`
62 | Used to pretty print the collection object while writing to a file
63 |
64 | - `-i`, `--interface-version`
65 | Specifies the interface version of the converter to be used. Value can be 'v2' or 'v1'. Default is 'v2'.
66 |
67 | - `-O`, `--options`
68 | Used to supply options to the converter, for complete options details see [here](/OPTIONS.md)
69 |
70 | - `-c`, `--options-config`
71 | Used to supply options to the converter through config file, for complete options details see [here](/OPTIONS.md)
72 |
73 | - `-t`, `--test`
74 | Used to test the collection with an in-built sample specification
75 |
76 | - `-v`, `--version`
77 | Specifies the version of the converter
78 |
79 | - `-h`, `--help`
80 | Specifies all the options along with a few usage examples on the terminal
81 |
82 |
83 | ### Usage
84 |
85 | - Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
86 | ```terminal
87 | $ gql2postman -s spec.yaml -o collection.json -p -O depth=3,includeDeprecatedFields=true
88 | ```
89 |
90 | - Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options via config file
91 | ```terminal
92 | $ gql2postman -s spec.yaml -o collection.json -p -c ./examples/cli-options-config.json
93 | ```
94 |
95 | - Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options with larger depth limit
96 | to make sure more detailed and nested data is generated.
97 | ```terminal
98 | $ gql2postman -s spec.yaml -o collection.json -p -O depth=7,includeDeprecatedFields=true,optimizeConversion=false
99 | ```
100 |
101 | - Testing the converter
102 | ```terminal
103 | $ gql2postman --test
104 | ```
105 |
106 |
107 | ## 🛠 Using the converter as a NodeJS module
108 |
109 | In order to use the convert in your node application, you need to import the package using `require`.
110 |
111 | ```javascript
112 | var Converter = require('graphql-to-postman')
113 | ```
114 |
115 | The converter provides the following functions:
116 |
117 | ### Convert
118 |
119 | The convert function takes in your GraphQL schema or SDL and converts it to a Postman collection.
120 |
121 | Signature: `convert (data, options, callback);`
122 |
123 | **data:**
124 |
125 | ```javascript
126 | { type: 'file', data: 'filepath' }
127 | OR
128 | { type: 'string', data: '' }
129 | ```
130 |
131 | **options:**
132 | ```javascript
133 | {
134 | depth: 4,
135 | includeDeprecatedFields: false,
136 | optimizeConversion: false
137 | }
138 | /*
139 | All three properties are optional. Check the options section below for possible values for each option.
140 | */
141 | ```
142 |
143 | **callback:**
144 | ```javascript
145 | function (err, result) {
146 | /*
147 | result = {
148 | result: true,
149 | output: [
150 | {
151 | type: 'collection',
152 | data: {..collection object..}
153 | }
154 | ]
155 | }
156 | */
157 | }
158 | ```
159 |
160 | ### Options
161 |
162 | - `depth` - The number of levels of information that should be returned. (A depth level of “1” returns that object and
163 | its properties. A depth of “2” will return all the nodes connected to the level 1 node, etc.)
164 |
165 | - `includeDeprecatedFields` - Generated queries will include deprecated fields or not.
166 |
167 | - `optimizeConversion` - Optimizes conversion for schemas with complex and nested input objects by reducing the depth to
168 | which input objects are resolved in GraphQL variables.
169 |
170 | ### ConversionResult
171 |
172 | - `result` - Flag responsible for providing a status whether the conversion was successful or not.
173 |
174 | - `reason` - Provides the reason for an unsuccessful conversion, defined only if result if `false`.
175 |
176 | - `output` - Contains an array of Postman objects, each one with a `type` and `data`. The only type currently supported is `collection`.
177 |
178 |
179 |
180 | ### Sample Usage
181 | ```javascript
182 | const fs = require('fs'),
183 | Converter = require('graphql-to-postman'),
184 | gqlData = fs.readFileSync('sample-spec.yaml', {encoding: 'UTF8'});
185 |
186 | Converter.convert({ type: 'string', data: gqlData },
187 | {}, (err, conversionResult) => {
188 | if (!conversionResult.result) {
189 | console.log('Could not convert', conversionResult.reason);
190 | }
191 | else {
192 | console.log('The collection object is: ', conversionResult.output[0].data);
193 | }
194 | }
195 | );
196 | ```
197 |
198 | ### Validate Function
199 |
200 | The validate function is meant to ensure that the data that is being passed to the [convert function](#convert-function) is a valid JSON object or a valid (YAML/JSON) string.
201 |
202 | The validate function is synchronous and returns a status object which conforms to the following schema
203 |
204 | #### Validation object schema
205 |
206 | ```javascript
207 | {
208 | type: 'object',
209 | properties: {
210 | result: { type: 'boolean'},
211 | reason: { type: 'string' }
212 | },
213 | required: ['result']
214 | }
215 | ```
216 |
217 | ##### Validation object explanation
218 | - `result` - true if the data is valid GraphQL and can be passed to the convert function
219 |
220 | - `reason` - Provides a reason for an unsuccessful validation of the specification
221 |
--------------------------------------------------------------------------------
/bin/gql2postman.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const _ = require('lodash'),
3 | { Command } = require('commander'),
4 | program = new Command(),
5 | Converter = require('../index.js'),
6 | fs = require('fs'),
7 | path = require('path'),
8 | availableOptions = _.map(Converter.getOptions(), 'id');
9 |
10 | let inputFile,
11 | outputFile,
12 | prettyPrintFlag,
13 | configFile,
14 | definedOptions,
15 | gqlInput,
16 | gqlData;
17 |
18 | /**
19 | * Parses comma separated options mentioned in command args and generates JSON object
20 | *
21 | * @param {String} value - User defined options value
22 | * @returns {Object} - Parsed option in format of JSON object
23 | */
24 | function parseOptions (value) {
25 | let definedOptions = value.split(','),
26 | parsedOptions = {};
27 |
28 | _.forEach(definedOptions, (definedOption) => {
29 | let option = definedOption.split('=');
30 |
31 | if (option.length === 2 && _.includes(availableOptions, option[0])) {
32 | try {
33 | // parse parsable data types (e.g. boolean, integer etc)
34 | parsedOptions[option[0]] = JSON.parse(option[1]);
35 | }
36 | catch (e) {
37 | // treat value as string if can not be parsed
38 | parsedOptions[option[0]] = option[1];
39 | }
40 | }
41 | else {
42 | console.warn('\x1b[33m%s\x1b[0m', 'Warning: Invalid option supplied ', option[0]);
43 | }
44 | });
45 |
46 | /**
47 | * As v2 interface uses parametersResolution instead of previous requestParametersResolution option,
48 | * override value of parametersResolution if it's not defined and requestParametersResolution is defined
49 | */
50 | if (_.has(parsedOptions, 'requestParametersResolution') && !_.has(parsedOptions, 'parametersResolution')) {
51 | parsedOptions.parametersResolution = parsedOptions.requestParametersResolution;
52 | }
53 | return parsedOptions;
54 | }
55 |
56 | program
57 | .version(require('../package.json').version, '-v, --version')
58 | .option('-s, --spec ', 'Convert given GraphQL schema to Postman Collection v2.0')
59 | .option('-o, --output