
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
github.com/owllaboratory/graphql_mongodb_golang_server
Since a few months I was curious to discover two new concepts: Golang and GraphQL A few days ago, I started to create my own GraphQL Golang server with MongoDB as a database.
I'm pretty sure it will help some people understand how a Golang GraphQL server works.
Of course I have very little experience under these two technologies, so I do not guarantee anything.
git clone https://github.com/OwlLaboratory/graphql_mongodb_golang_server $HOME/go/src/github.com/OwlLaboratory/graphql_mongodb_golang_server
cd $HOME/go/src/github.com/OwlLaboratory/graphql_mongodb_golang_server/
go get ./...
go build server.go
./server
Then: open http://localhost:8080
For the server part I based on the neelance server (he is the main creator of GopherJS)
For the ODM I based on mongodm (which I slightly modified)
MongoDB is configured on localhost:27017 by default (you can change config in mongo.go)
I try to follow some best practices and implement a CLEAR architecture for a module
I implemented a simple CRUD on a Mongo collection called "Channel" and defined like this:
{
id: ObjectID,
name: string,
platform {
name: string
},
created: MongoDate
updated: MongoDate
}
channel(id: String!): Channel
channels(first: Int, offset: Int): [Channel]
createChannel(input: CreateChannelInput!): Channel
updateChannel(input: UpdateChannelInput!): Channel
deleteChannel(input: DeleteChannelInput!): Channel
mutation createChannel {
createChannel(input: {channel: {name: "Channel 1", platform: {name: "Platform for channel 1"}}}) {
id
name
platform {
name
}
}
}
mutation updateChannel {
updateChannel(input: {id: "5a9b13a7e1382307023003d7", patch: {platform: {name: "Yolo"}}}) {
name
platform {
name
}
}
}
mutation deleteChannel {
deleteChannel(input: {id: "5a9b13a7e1382307023003d7"}) {
name
}
}
{
channels(first: 1, offset: 1) {
id
name
}
}
{
channel(id: "5a9b13a7e1382307023003d7") {
name
platform {
name
}
}
}
I tried to implement a clear architecture rather than storing everything in a "models" package
Each collection is represented as an independent package containing all the resources needed for GraphQL Server.
git clone https://github.com/OwlLaboratory/graphql_mongodb_golang_server $HOME/go/src/github.com/OwlLaboratory/graphql_mongodb_golang_server
cd $HOME/go/src/github.com/OwlLaboratory/graphql_mongodb_golang_server/
go get ./...
go build server.go
./server
Then: open http://localhost:8080
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.