Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
package gopher
import "github.com/graphql-go/graphql"
type Resolver interface {
// ResolveGophers should return a list of all gophers in the repository
ResolveGophers(p graphql.ResolveParams) (interface{}, error)
// ResolveGopher is used to respond to single queries for gophers
ResolveGopher(p graphql.ResolveParams) (interface{}, error)
}
@percybolmer
percybolmer / GraphQL-main.go
Last active September 7, 2021 06:37
Graphql
// This package is a demonstration how to build and use a GraphQL server in Go
package main
import (
"log"
"net/http"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
)
@percybolmer
percybolmer / gopher.go
Created September 6, 2021 18:12
Graphql
package schemas
import "github.com/graphql-go/graphql"
// GopherType is the gopher graphQL Object that we will send on queries
// Here we define the structure of the gopher
// This has to match the STRUCT tags that are sent out later
var GopherType = graphql.NewObject(graphql.ObjectConfig{
Name: "Gopher",
// Fields is the field values to declare the structure of the object
{
"data": {
"gophers": [
{
"name": "original",
"profession": "logotype",
"jobs": {
"title": "Original Gopher By Renee Fench",
"years": 12,
}
@percybolmer
percybolmer / GraphQL-ExampleQueryV2.graphql
Last active September 5, 2021 20:07
GraphQL--Query example
query {
gopher { // Object
id // Field
name // Field
}
jobs { // Object
title // field
years // Field
}
// Package main runs the tavern and performs an Order
package main
import (
"github.com/google/uuid"
"github.com/percybolmer/tavern/domain/product"
"github.com/percybolmer/tavern/services/order"
servicetavern "github.com/percybolmer/tavern/services/tavern"
)
// Package product
// Product is an aggregate that represents a product.
package product
import (
"errors"
"github.com/google/uuid"
"github.com/percybolmer/tavern"
)
@percybolmer
percybolmer / Go-DDD-ItemTavern.go
Last active September 4, 2021 18:54
#ddd-tavern
package tavern
import "github.com/google/uuid"
// Item represents a Item for all sub domains
type Item struct {
ID uuid.UUID
Name string
Description string
}
func Test_MongoTavern(t *testing.T) {
// Create OrderService
products := init_products(t)
os, err := order.NewOrderService(
order.WithMongoCustomerRepository("mongodb://localhost:27017"),
order.WithMemoryProductRepository(products),
)
if err != nil {
t.Error(err)
// AddCustomer will add a new customer and return the customerID
func (o *OrderService) AddCustomer(name string) (uuid.UUID, error) {
c, err := customer.NewCustomer(name)
if err != nil {
return uuid.Nil, err
}
// Add to Repo
err = o.customers.Add(c)
if err != nil {
return uuid.Nil, err