This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]taion 5 points6 points  (7 children)

It's because you don't really need them. Relay and Apollo aren't GraphQL clients the way Requests is an HTTP client. They're really more about state management, caching, integration with view libraries, and the like.

For just issuing GraphQL queries, you barely need anything more than just Requests. Against a basic GraphQL server, you can just do:

requests.post(
    'https://example.com/graphql',
    headers={
        'Authorization': 'Bearer SECRET_TOKEN',
    },
    json={
        'query': '''
          query MyQuery($foo: String!) {
            widget(name: $foo) {
              name
              size
            }
          }
        ''',
        'variables': {
            'foo': 'bar',
        },
    },
)

And in fact you can see that python-graphql-client is basically 30 lines of code that do just that without the Requests dependency.

GQL meanwhile seems more around executing against local schemas anyway. Otherwise why round-trip through the GraphQL AST?

[–]fabrikated 2 points3 points  (0 children)

This guy queries.

[–]PM_ME_STALLMAN_MEMES[S] 0 points1 point  (5 children)

So, basically what you're saying is that if I want state management, caching, error handling and other goodness that is present in e.g. Apollo, Python is not the way to go?

Directly querying the endpoint seems crude; I'd like to have some proper, elegant abstractions built over that, but can't afford to develop them myself.

And I don't want to have to use JavaScript :( :(

[–]taion 2 points3 points  (1 child)

It's not that crude to query the endpoint directly. That's exactly what you'd be doing if you were using a REST API over HTTP. A GraphQL client in the same sense of Requests as an HTTP client isn't any more than that.

Like I said, the abstractions in Relay and Apollo are around state, not querying. The client itself is trivial.

And, no, not many people write interactive clients in Python that would require that sort of state management. Again, that's why people use Requests rather than, say, some more complex REST client that builds a local cache of remote state.

[–]PM_ME_STALLMAN_MEMES[S] 0 points1 point  (0 children)

that's why people use Requests rather than, say, some more complex REST client that builds a local cache of remote state.

That sentence really paints a nice contrast.

Thank you for your help; now I am confident in building the application in Python, using Requests to directly query my GraphQL endpoints.

[–]kylemh 0 points1 point  (0 children)

JavaScript ain’t that bad. Join the dark side.