Giter Club home page Giter Club logo

go-meetup's Introduction

go-meetup

A meet-up service designed in Go with GraphQL, CockroachDB and gqlgen

Setting custom resolver on generated models with gqlgen

After the models are generated from provided SDL, wire them up as custom schema's by adding following to gqlgen.yml models key;

User:
  model: github.com/Akshit8/go-meetup/graph/model.User
    fields:
      meetups:
        resolver: true
Meetup:
  model: github.com/Akshit8/go-meetup/graph/model.Meetup
    fields:
      user:
        resolver: true

Using Postgres for development

CockroachDB supports the PostgreSQL wire protocol, so available PostgreSQL client drivers and ORMs mostly work with CockroachDB. So for development we'll use postgres and we can later connect to cockroachDB cluster for production.

# setting postgres container
docker-compose up -d
docker exec -it postgresdb createdb --username=root --owner=root meetup

# setting migration with golang migrate
mkdir db/migration
migrate create -ext sql -dir db/migration -seq init

# migrate up
make migrationup

Seeding PG db manually

docker exec -it postgresdb psql -U root -d meetup

INSERT INTO users (username, email) VALUES ('bob', '[email protected]');
INSERT INTO users (username, email) VALUES ('jon', '[email protected]');
INSERT INTO users (username, email) VALUES ('jane', '[email protected]');

INSERT INTO meetups (name, description, user_id) VALUES ('My first meetup', 'This is a description', 1);
INSERT INTO meetups (name, description, user_id) VALUES ('My second meetup', 'This is a description', 1);

Optimising N + 1 queries with dataloaders

  • Some GraphQL queries can make hundreds of database queries, often with mostly repeated data.
  • Dataloader is a way to group up all of those concurrent requests, take out any duplicates, and store them in case they are needed later on in request. The dataloader is just that, a request-scoped batching and caching solution popularised by facebook.
  • We’re going to use dataloaden to build our dataloaders.
go get github.com/vektah/dataloaden
mkdir dataloader
cd dataloader
go run github.com/vektah/dataloaden UserLoader string *github.com/Akshit8/go-meetup/graph/model.User

Makefile specs

  • git - git add - commit - push commands
  • start - start the application without build
  • gen - generated graphql-go code for graphql SDL
  • migrationUp - migrate db to new migrations
  • migrationDown - rollback db to previous stage

References

go-pg

Author

Akshit Sadana [email protected]

License

Licensed under the MIT License

go-meetup's People

Contributors

akshit8 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.