Skip to content

Commit

Permalink
Issue aubm#68 GraphQL support
Browse files Browse the repository at this point in the history
  • Loading branch information
omarlopesino committed Jun 5, 2024
1 parent 69ccdeb commit 8bce871
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
30 changes: 18 additions & 12 deletions postman/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -58,3 +59,8 @@ type KeyValuePair struct {
Value interface{}
Description string
}

type GraphQLBody struct {
Query string `json:"query,omiempty"`
Variables string `json:"variables,omiempty"`
}
1 change: 1 addition & 0 deletions postman/collection_v210.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions postman/collection_v210_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions themes/helper_curl_snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
}

Expand All @@ -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))
}
}

Expand Down

0 comments on commit 8bce871

Please sign in to comment.