GraphQL is a layer you can integrate to your backend to change the way you communicate with your client and think stuff about your model. While express and MongoDB are very common on my daily work, this is the all-in-one boilerplate i was needing to give GraphQL a try.
Here you can found some examples, and some of your devops just done. (transpile, lintern, initial standard configurations).
- yarn install
- yarn dev
- yarn install
- yarn build
- yarn serve
One endpoint to rule them all
The idea beahind GraphQL is to resume all posible model handling behind a unique endpoint, and a specialized query language. The application server only expose:
With a little configuration already implemented on this seed:
app.use('/graphql', graphqlHTTP({
schema: schema,
graphiql: true
}))
The server expose a GQL query web-client, useful for query testing, practice and of course having some fun...
While running the server on dev or production, GraphQL express endpoint is behind cors middleware.
This let the app client and server work through different ports on dev stage. But this is not desirable feature in a regular production app.
mutation{
addUser(
data: {
email: "franco@protonmail.com",
name: "Franco Rabaglia"
}) {
_id
email
name
}
}
mutation{
updateUser(
id: "5929b0e36840b54c56c73db2",
data: {
email: "franko@genosha.uy",
name: "Franko Rabaglio"
}) {
_id
email
name
}
}
mutation{
removeUser(id: "5929b0e36840b54c56c73db2") {
_id
email
name
}
}
mutation{
addPost(data: {
uid:"5929b50c03f15b4d0129767a",
title: "GraphQL title",
body: "GraphQL body"
}) {
_id
uid
title
body
}
}
Play adding and removing fields!
query{
User(id:"5929b50c03f15b4d0129767a") {
_id
email
name
posts {
_id
uid
title
body
}
}
}
query{
Users {
_id
email
name
posts {
_id
uid
title
body
}
}
}