This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"gophers": [ | |
{ | |
"name": "original", | |
"profession": "logotype", | |
"jobs": { | |
"title": "Original Gopher By Renee Fench", | |
"years": 12, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query { | |
gopher { // Object | |
id // Field | |
name // Field | |
} | |
jobs { // Object | |
title // field | |
years // Field | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package product | |
// Product is an aggregate that represents a product. | |
package product | |
import ( | |
"errors" | |
"github.com/google/uuid" | |
"github.com/percybolmer/tavern" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |