httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
33.86k stars 3.68k forks source link

Native Graphql Support #914

Open collegeimprovements opened 4 years ago

collegeimprovements commented 4 years ago

Currently to hit any Graphql query or mutation, we need to convert them first to json. It would be really great if we can copy the query directly from graphiql and then pass it to httpie.

Is it possible with httpie natively ? One of the vs-code extension is already doing it. Is the same/similar thing possible with httpie ?

jkbrzt commented 4 years ago

@collegeimprovements currently not possible, sadly.

I’d definitely like to look into some form of native GraphQL support — what other GraphQL-related features would you like to see in HTTPie?

collegeimprovements commented 4 years ago

tldr; Example:

http query.graphql --schema schema.json

☝🏼Extension can be anything like: http or gql or graphql or post etc. The idea is user should be able to directly copy-paste the query from graphiql or graphql-client. He should not be worried about json conversion. 👉🏼 --schema file is optional. When provided the query is parsed & validated against it first. [might be out of scope]


Feature Requests:

  1. Send graphql request.
  2. Variable interpolation in httpie request. e.g. HOST and Request headers are different for dev and `prod.
  3. Graphql introspection if possible.

I think with this two features we can compose many powerful apps. I don't know if the following falls into httpie's scope. E.g. We can download graphql's schema.json file and then we can have autocomplete and validation support.

With this two - Vim, VSCode, IDEs can implement: validation, autocomplete and response features for any graphql schema even with offline support. I was trying to send "graphql" queries from vim to terminal, but could not find a tool that can do that.

Useful Links:

gmelodie commented 4 years ago

Hey there! I'm thinking about working on this one if that's ok.

I guess this can be broke down to three ideas/PRs:

  1. Receive a GraphQL request just as a JSON request (i.e. http httpbin.org/post < graphql.schema)
  2. Download a JSON request (--save or --download)
  3. Check GraphQL schema against JSON request file 3.1. Receive GraphQL schema (using 1) 3.2. Generate JSON request (using 2) 3.3. Compare generated JSON and given JSON

Obs: I think introspection would be in scope but as far as I understand (correct me if I'm wrong) it comes down to just a regular query, so I guess you'll end up having to write that yourself as a user (i.e. wouldn't be an actual httpie feature).

schmidlidev commented 3 years ago

Am I either misunderstanding the issue, or has this been added?

http POST https://api.spacex.land/graphql/ query="{ launchesPast(limit: 1) { mission_name id } }"

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 77
Content-Type: application/json; charset=utf-8
Date: Sun, 06 Dec 2020 23:36:39 GMT
Etag: W/"4d-gZOMzXfj+ItRDOmYGjTauITd5rQ"
Server: Cowboy
Via: 1.1 vegur
X-Powered-By: Express

{
    "data": {
        "launchesPast": [
            {
                "id": "109",
                "mission_name": "Starlink-15 (v1.0)"
            }
        ]
    }
}

And it works with 'messy' whitespace too (directly ctrl-a + ctrl-c'd from graphiql)

http POST https://api.spacex.land/graphql/ query="{                                              
  launchesPast(limit: 1) {
    mission_name
    id
  }
}
"
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 77
Content-Type: application/json; charset=utf-8
Date: Sun, 06 Dec 2020 23:40:20 GMT
Etag: W/"4d-gZOMzXfj+ItRDOmYGjTauITd5rQ"
Server: Cowboy
Via: 1.1 vegur
X-Powered-By: Express

{
    "data": {
        "launchesPast": [
            {
                "id": "109",
                "mission_name": "Starlink-15 (v1.0)"
            }
        ]
    }
}
jkbrzt commented 3 years ago

@schmidlidev GraphQL requests are regular HTTP requests so they have always been supported. This issue is about deeper GraphQL-specific features.

abitrolly commented 3 years ago

It would be nice to get GraphQL pagination supported natively. To fetch more than 100 results from GitLab API https://docs.gitlab.com/ee/api/graphql/getting_started.html#pagination on one go.