AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
240 stars 21 forks source link

support of vscode-restclient style GraphQL #10

Closed yarick123 closed 3 years ago

yarick123 commented 3 years ago

I tried the GraphQL with the extension exactly the same way as by vscode-restclient:

POST {{server}}
Content-Type: application/json
X-REQUEST-TYPE: GraphQL

query {
    test(id: 95, url: "/test95") { Url Name }
}

but got an error message, that the json is incorrect. Could you please show an working sample of GraphQL querying with the extension?

P.S. I used the extension version 1.6.0 on vscode 1.53.0 on windows

AnWeber commented 3 years ago

It will not work this way since httpyac is not a fork of vscode-restclient and the hack with the request header is intentionally not implemented. I want to support graphql even better, but for now that JSON still needs to be created manually.

POST {{server}}
Content-Type: application/json

{
"query": "{test(id: 95, url: "/test95") { Url Name }}"
}

My current idea would be to implement the following format.

POST {{server}}
Content-Type: application/json

gql`
query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}
`

However, I want to read through the specification more before implementing this so I don't overlook special cases like graphql fragments.

I need to dig deeper into graphql and be able to run a use case. I am grateful for help.

AnWeber commented 3 years ago

I have discarded the idea with gql`. With the new version the query should work without the X-REQUEST-TYPE header. Fragments are also supported.

fragment IOParts on Repository {
  description
  diskUsage
}

POST https://api.github.com/graphql
Content-Type: application/json
Authorization: Bearer {{git_api_key}}

query repositoryQuery($name: String!, $owner: String!) {
  repository(name: $name, owner: $owner) {
    name
    fullName: nameWithOwner
    ...IOParts
    forkCount
    watchers {
        totalCount
    }
  }
}

{
    "name": "vscode-httpyac",
    "owner": "AnWeber"
}