cli icon indicating copy to clipboard operation
cli copied to clipboard

Native Graphql Support

Open collegeimprovements opened this issue 4 years ago • 6 comments

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 ?

collegeimprovements avatar May 12 '20 06:05 collegeimprovements

@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?

jkbrzt avatar May 12 '20 13:05 jkbrzt

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:

  • https://github.com/graphql/graphiql/tree/master/packages/graphql-language-service
  • https://github.com/apollographql/apollo-tooling#apollo-clientdownload-schema-output

collegeimprovements avatar May 12 '20 15:05 collegeimprovements

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).

gmelodie avatar Jun 16 '20 13:06 gmelodie

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)"
            }
        ]
    }
}

schmidlidev avatar Dec 06 '20 23:12 schmidlidev

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

jkbrzt avatar Dec 07 '20 08:12 jkbrzt

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.

abitrolly avatar May 08 '21 07:05 abitrolly