diff --git a/postman/collection.go b/postman/collection.go index 7c7f16e..428db6f 100644 --- a/postman/collection.go +++ b/postman/collection.go @@ -9,18 +9,19 @@ type Collection struct { } type Request struct { - ID string - Name string - Description string - Method string - URL string - PayloadType string - PayloadRaw string - PayloadParams []KeyValuePair - PathVariables []KeyValuePair - Headers []KeyValuePair - Responses []Response - Tests string + ID string + Name string + Description string + Method string + URL string + PayloadType string + PayloadRaw string + PayloadGraphQL GraphQLBody + PayloadParams []KeyValuePair + PathVariables []KeyValuePair + Headers []KeyValuePair + Responses []Response + Tests string } type Response struct { @@ -58,3 +59,8 @@ type KeyValuePair struct { Value interface{} Description string } + +type GraphQLBody struct { + Query string `json:"query,omiempty"` + Variables string `json:"variables,omiempty"` +} \ No newline at end of file diff --git a/postman/collection_v210.go b/postman/collection_v210.go index f69ba27..98ccd0e 100644 --- a/postman/collection_v210.go +++ b/postman/collection_v210.go @@ -22,6 +22,7 @@ type collectionV210Item struct { Raw string `json:"raw"` FormData []collectionV210KeyValuePair `json:"formdata,omitempty"` UrlEncoded []collectionV210KeyValuePair `json:"urlencoded,omitempty"` + GraphQL GraphQLBody `json:"graphql,omitempty"` } `json:"body"` Url struct { Raw string `json:"raw"` diff --git a/postman/collection_v210_parser.go b/postman/collection_v210_parser.go index a3b6594..1750764 100644 --- a/postman/collection_v210_parser.go +++ b/postman/collection_v210_parser.go @@ -63,6 +63,7 @@ func (p *CollectionV210Parser) computeItem(parentFolder *Folder, items []collect URL: item.Request.Url.Raw, PayloadType: item.Request.Body.Mode, PayloadRaw: item.Request.Body.Raw, + PayloadGraphQL: item.Request.Body.GraphQL, Tests: p.parseRequestTests(item), PathVariables: p.parseRequestPathVariables(item), PayloadParams: p.parseRequestPayloadParams(item), diff --git a/themes/helper_curl_snippet.go b/themes/helper_curl_snippet.go index f340e10..3b1d4ce 100644 --- a/themes/helper_curl_snippet.go +++ b/themes/helper_curl_snippet.go @@ -18,6 +18,8 @@ func curlSnippet(request postman.Request) string { curlSnippet += ` -H "Content-Type: application/x-www-form-urlencoded"` } else if request.PayloadType == "params" || request.PayloadType == "formdata" { curlSnippet += ` -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"` + } else if request.PayloadType == "graphql" { + curlSnippet += ` -H "Content-Type: application/json"` } } @@ -40,6 +42,10 @@ func curlSnippet(request postman.Request) string { curlSnippet += fmt.Sprintf(` -F "%v=%v"`, data.Key, data.Value) } } + } else if request.PayloadType == "graphql" { + // Query and variables breaklines are removed + // as curl may not interpret correctly the JSON. + curlSnippet += fmt.Sprintf(" --data '{\"query\": \"%s\", \"variables\": %s}'", strings.Replace(request.PayloadGraphQL.Query, "\n", " ", -1), strings.Replace(request.PayloadGraphQL.Variables, "\n", " ", -1)) } }