We use GraphQL to get better DX (developer experience) and reduce communication cost between frontend devs and backend devs.
It turns out to be a huge success! The dev team is quite happy with the result!
Today I want to share some experiences & some sample code!
My favorite part about graphql is that the communication between frontend devs and backend devs becomes much easier!
When the backend devs finish the backend part, graphql automatically generates API documentation & testing tools!
For better demonstration, I create a sample project on Github!
It's a simple e-commerce project, with
comments in the API.
And users can subscribe to the newsletter, insert new data into the
The project link is here
The source code is here
In graphql, for 'reading data' APIs, we call it 'query'
For 'updating data' APIs, we call it 'mutation'
Check out the above folders, you can see each API is a single file, makes its very easy to understand.
And then you can try out the powerful tool 'graphiql' - it provides documentation & testing tool at the same time!
I deploy a sample graphiql online so you can play with it directly!
This tool is my favorite thing in the graphql ecosystem!
There's two way of implementing api in graphql: schema-first and code-first.
For schema-frst with laravel, you can use
For code-first with laravel, you can use
I won't mention the differences between the two ways here.
I personally prefer code-first philosophy. I think it's easier to understand & implement.
So I'll use https://github.com/rebing/graphql-laravel in the example project.
They both use https://github.com/webonyx/graphql-php as the fundamental components
So don't worry, they share the same core concepts!
Graphiql is a graphql official library.
Use https://github.com/mll-lab/laravel-graphiql to install it easily.
With the above packages & the example project I provided https://github.com/howtomakeaturn/graphql-laravel-example
You should be able to implement your own graphql APIs in your project!
I will realease more sample code in the following articles, so you won't get blocked by the advanced features with graphql!
(This is series article. More content will be released soon.)