Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/owllaboratory/graphql_mongodb_golang_server

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/owllaboratory/graphql_mongodb_golang_server

  • v0.0.0-20180303224951-af892cb21479
  • Source
  • Go
  • Socket score

Version published
Created
Source

Simple GraphQL + MongoDB Golang server

Why this repo ?

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.

Run 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

Server + ODM

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
}

Available queries:

		channel(id: String!): Channel
		channels(first: Int, offset: Int): [Channel]

Available mutations:

		createChannel(input: CreateChannelInput!): Channel
		updateChannel(input: UpdateChannelInput!): Channel
		deleteChannel(input: DeleteChannelInput!): Channel

Example of GraphQL requests:

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
    }
  }
}

Architecture

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.

Example for channel collection

module

Run 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

Package last updated on 03 Mar 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc