In the new year, I want to learn how to use GraphQL. Why not using this technology for personal project or at work. So, for now I will use it with MongoDB at backend and VueJS 2.0 at frontend.
I have a question about how to send query and mutations. Do I need to send directly query like :
query {
posts {
_id
title
content
}
}
and mutations from client-side (write it at client side) and send it to server endpoint ? (it is secure ?) .
else I was thinking about writing all my queries at backend and simply request post request with action param like QUERY_POST
and at backend I find my query for QUERY_POST
and play GraphQL query and send it at vue-side.
What did you think, what is the best way ? I'm a little lost about it. Storing queries and mutations at client side or at server-side ?
Thanks!
Your question is a bit confusing... the whole point of GraphQL is the capability to request everything you need (and nothing more) in 1 query. A mutation is a specific type of query which will modify data on your back-end. GraphQL queries are to be issued by the client.
After this is your responsibility on server-side to implement authentication and access control so that your data is not exposed to the world.
If you are new to GraphQL, I recommend you to have a look at this excellent tutorial: https://learngraphql.com/basics/querying-graphql
You may be interested in https://www.graph.cool/ too.
Hope this helps :-)