I was going to write an implementation of Hashnodes API for Laravel/Composer. However I stumbled as it hit me that there are no clear way in PHP to generate GraphQL queries.
I hope some of you here have experience and would like to share that.
Hey π Emil Moe, an implementation in PHP would be really great. Unfortunately, I'm not an expert in PHP, but I was under the impression that there will be a GraphQL client library in the PHP ecosystem. If that's not the case then it seems like an interesting project π to me. In the meantime, we can make raw HTTP requests to the API to do our thing. Here is an example snippet which does that (pardon me! It's in JS)
fetch('api.hashnode.com', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': "<your token here>"},
body: JSON.stringify({
query: 'query { storiesFeed(type: GLOBAL){ title } }'
}),
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res)))
As a client I would go for github.com/softonic/graphql-client something like this. you could create an object / array based system but creating a nested graph i a pain in the ass and just writing it declarative makes a lot of sense to me.
Clark Nelson
Developer
If you are looking at using Laravel / Composer anyways, you should consider Craft CMS.
They have just added a basic GraphQL implementation with more to come.