Picking a GraphQL Client
There are a bunch of GraphQL clients that exist. How do you know which one is right for you? I'm going to discuss some of your options, but let's cut to the chase:
If you're building a front-end web-app, I recommend you use Apollo Client. If you want to take my recommendation, you can just skip to the next chapter.
But for those of you who are making a years-long, fundamental architectural decision for your team - you might want to read below to get a lay of the land.
GraphQL is just JSON over HTTP (well, usually)#
Because GraphQL servers are typically over HTTP, you don't have to use a client library at all. You can just use whatever HTTP request library you were already using and it will "work".
GraphQL is in this sense, more of a language/protocol pair than a specific library and it will work fine in any language where you can form queries and parse JSON - making it suitable for mobile apps, compiled clients, etc.
So as we covered in the first chapter, you can query a GraphQL server using curl
,
xxxxxxxxxx
{
query: "query MyQuery { viewer {name} }",
variables: {},
operationName: "MyQuery"
}
The operationName
here is the name of your query.
With curl, it would look like this:
xxxxxxxxxx
curl \
-X POST \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" \
--data '...' \
https://github.com/graphql