diff --git a/README.md b/README.md index 5110daa3..a417804e 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,38 @@ query ($name: String!, $owner: String!) { } ``` +Alternatively, you can use the http method `GRAPHQL`: +```http +GRAPHQL https://api.github.com/graphql +Content-Type: application/json +Authorization: Bearer xxx + +query ($name: String!, $owner: String!) { + repository(name: $name, owner: $owner) { + name + fullName: nameWithOwner + description + diskUsage + forkCount + stargazers(first: 5) { + totalCount + nodes { + login + name + } + } + watchers { + totalCount + } + } +} + +{ + "name": "vscode-restclient", + "owner": "Huachao" +} +``` + ## Making cURL Request ![cURL Request](https://raw.githubusercontent.com/Huachao/vscode-restclient/master/images/curl-request.png) We add the capability to directly run [curl request](https://curl.haxx.se/) in REST Client extension. The issuing request command is the same as raw HTTP one. REST Client will automatically parse the request with specified parser. diff --git a/language-configuration.json b/language-configuration.json index eafc5230..81b34984 100644 --- a/language-configuration.json +++ b/language-configuration.json @@ -15,8 +15,8 @@ ], "folding": { "markers": { - "start": "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|CONNECT|TRACE|LOCK|UNLOCK|PROPFIND|PROPPATCH|COPY|MOVE|MKCOL|MKCALENDAR|ACL|SEARCH|curl)\\s+", + "start": "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|CONNECT|TRACE|LOCK|UNLOCK|PROPFIND|PROPPATCH|COPY|MOVE|MKCOL|MKCALENDAR|ACL|SEARCH|GRAPHQL|curl)\\s+", "end": "^#{3,}$" } } -} \ No newline at end of file +} diff --git a/src/utils/httpRequestParser.ts b/src/utils/httpRequestParser.ts index 1a247690..4a2e4a97 100644 --- a/src/utils/httpRequestParser.ts +++ b/src/utils/httpRequestParser.ts @@ -82,10 +82,10 @@ export class HttpRequestParser implements RequestParser { removeHeader(headers, 'content-length'); // check request type - const isGraphQlRequest = getHeader(headers, 'X-Request-Type') === 'GraphQL'.toLowerCase(); + const isGraphQlRequest = requestLine.method.toLowerCase() === 'graphql' || getHeader(headers, 'X-Request-Type') === 'GraphQL'.toLowerCase(); if (isGraphQlRequest) { removeHeader(headers, 'X-Request-Type'); - + requestLine.method = 'POST'; // a request doesn't necessarily need variables to be considered a GraphQL request const firstEmptyLine = bodyLines.findIndex(value => value.trim() === ''); if (firstEmptyLine !== -1) { @@ -152,7 +152,7 @@ export class HttpRequestParser implements RequestParser { let url: string; let match: RegExpExecArray | null; - if (match = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|CONNECT|TRACE|LOCK|UNLOCK|PROPFIND|PROPPATCH|COPY|MOVE|MKCOL|MKCALENDAR|ACL|SEARCH)\s+/i.exec(line)) { + if (match = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|CONNECT|TRACE|LOCK|UNLOCK|PROPFIND|PROPPATCH|COPY|MOVE|MKCOL|MKCALENDAR|ACL|SEARCH|GRAPHQL)\s+/i.exec(line)) { method = match[1]; url = line.substr(match[0].length); } else { @@ -228,4 +228,4 @@ export class HttpRequestParser implements RequestParser { private getLineEnding(contentTypeHeader: string | undefined) { return MimeUtility.isMultiPartFormData(contentTypeHeader) ? '\r\n' : EOL; } -} \ No newline at end of file +}