You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.[Command Line Interface](#command-line-interface)
30
+
1.[Options](#options)
31
+
2.[Usage](#usage)
32
+
3.[Using the converter as a NodeJS module](#using-the-converter-as-a-nodejs-module)
33
+
1.[Convert Function](#convert)
34
+
2.[Options](#options)
35
+
3.[ConversionResult](#conversionresult)
36
+
4.[Sample usage](#sample-usage)
37
+
5.[Validate function](#validate-function)
38
+
4.[Conversion Schema](#conversion-schema)
39
+
40
+
---
41
+
42
+
---
43
+
44
+
45
+
## 💭 Getting Started
46
+
47
+
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.
48
+
49
+
```terminal
50
+
$ npm install graphql-to-postman
51
+
```
52
+
53
+
If you want to use the converter in the CLI, install it globally with NPM:
54
+
55
+
```terminal
56
+
$ npm i -g graphql-to-postman
57
+
```
58
+
59
+
60
+
## 📖 Command Line Interface
61
+
62
+
The converter can be used as a CLI tool as well. The following [command line options](#options) are available.
63
+
64
+
`gql2postman [options]`
65
+
66
+
### Options
67
+
68
+
-`-s <source>`, `--spec <source>`
69
+
Used to specify the GraphQL specification (file path) which is to be converted
70
+
71
+
-`-o <destination>`, `--output <destination>`
72
+
Used to specify the destination file in which the collection is to be written
73
+
74
+
-`-p`, `--pretty`
75
+
Used to pretty print the collection object while writing to a file
76
+
77
+
-`-i`, `--interface-version`
78
+
Specifies the interface version of the converter to be used. Value can be 'v2' or 'v1'. Default is 'v2'.
79
+
80
+
-`-O`, `--options`
81
+
Used to supply options to the converter, for complete options details see [here](/OPTIONS.md)
82
+
83
+
-`-c`, `--options-config`
84
+
Used to supply options to the converter through config file, for complete options details see [here](/OPTIONS.md)
85
+
86
+
-`-t`, `--test`
87
+
Used to test the collection with an in-built sample specification
88
+
89
+
-`-v`, `--version`
90
+
Specifies the version of the converter
91
+
92
+
-`-h`, `--help`
93
+
Specifies all the options along with a few usage examples on the terminal
94
+
95
+
96
+
### Usage
97
+
98
+
- Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
- 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
109
+
to make sure more detailed and nested data is generated.
console.log('Could not convert', conversionResult.reason);
203
+
}
204
+
else {
205
+
console.log('The collection object is: ', conversionResult.output[0].data);
206
+
}
207
+
}
208
+
);
209
+
```
210
+
211
+
### Validate Function
212
+
213
+
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.
214
+
215
+
The validate function is synchronous and returns a status object which conforms to the following schema
216
+
217
+
#### Validation object schema
218
+
219
+
```javascript
220
+
{
221
+
type:'object',
222
+
properties: {
223
+
result: { type:'boolean'},
224
+
reason: { type:'string' }
225
+
},
226
+
required: ['result']
227
+
}
228
+
```
229
+
230
+
##### Validation object explanation
231
+
-`result` - true if the data is valid GraphQL and can be passed to the convert function
232
+
233
+
-`reason` - Provides a reason for an unsuccessful validation of the specification
0 commit comments