File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1
1
export default `
2
- usage: graphql-js-schema-fetch --url my-api.com [--method=POST] [--header="...", --header="..."]
2
+ usage: graphql-js-schema-fetch [URL | --url] [--method=POST] [--header="...", --header="..."]
3
3
4
4
Fetch the json representation of a GraphQL Schema from a live server.
5
5
6
- arguments :
6
+ Arguments :
7
7
--url The URL where you GraphQL API resides.
8
8
--method The HTTP method to use during the fetch (default: 'POST')
9
9
--header[,--header] Any headers to send along with the request. Specify this
10
10
option multiple times for multiple headers. (example:
11
11
--header "Authorization: Basic abc123" --header "X-Version: 1")
12
+
13
+ Examples:
14
+ Fetch schema with default headers:
15
+ graphql-js-schema-fetch https://api.example.com > schema.json
16
+
17
+ Fetch schema with authorization header:
18
+ graphql-js-schema-fetch https://api.example.com \
19
+ --header "Authorization: Basic abc123" > schema.json
20
+
21
+ Fetch schema with multiple headers:
22
+ graphql-js-schema-fetch https://api.example.com \
23
+ --header "Authorization: Basic abc123" \
24
+ --header "X-Version: 1" > schema.json
12
25
` ;
Original file line number Diff line number Diff line change @@ -13,11 +13,12 @@ export default function parseArgs(rawArgs) {
13
13
}
14
14
} ) ;
15
15
16
- if ( args . help || ! args . url ) {
16
+ const url = args . _ [ 0 ] || args . url ;
17
+
18
+ if ( args . help || ! url ) {
17
19
return { showHelp : true } ;
18
20
}
19
21
20
- const url = args . url ;
21
22
const method = args . method ;
22
23
23
24
const headers = [ ] . concat ( args . header ) . reduce ( ( headerAcc , header ) => {
Original file line number Diff line number Diff line change @@ -39,4 +39,16 @@ suite('This will test arg parsing', () => {
39
39
assert . deepEqual ( args . headers . Accept , 'application/json' ) ;
40
40
assert . deepEqual ( args . headers [ 'Content-Type' ] , 'application/json' ) ;
41
41
} ) ;
42
+
43
+ test ( 'it supports positional url argument' , ( ) => {
44
+ const args = parseArgs ( [ 'https://graphql.example.com' ] ) ;
45
+
46
+ assert . deepEqual ( args . url , 'https://graphql.example.com' ) ;
47
+ } ) ;
48
+
49
+ test ( 'it supports named url argument' , ( ) => {
50
+ const args = parseArgs ( [ '--url' , 'https://graphql.example.com' ] ) ;
51
+
52
+ assert . deepEqual ( args . url , 'https://graphql.example.com' ) ;
53
+ } ) ;
42
54
} ) ;
You can’t perform that action at this time.
0 commit comments