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
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) | |
// ResolveJobs is used to find Jobs | |
ResolveJobs(p graphql.ResolveParams) (interface{}, error) | |
} | |
// GopherService is the service that holds all repositories |
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
// memory is a in memory data storage solution for Job | |
package job | |
import ( | |
"errors" | |
"sync" | |
) | |
// InMemoryRepository is a storage for jobs that uses a map to store them | |
type InMemoryRepository struct { |
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 job | |
// Repository is used to specify whats needed to fulfill the job storage requirements | |
type Repository interface { | |
// GetJobs will search for all jobs related to and EmployeeID | |
GetJobs(employeeID string) ([]Job, error) | |
} | |
// Job is how a job is presented | |
type Job struct { |
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 | |
type Repository interface { | |
GetGophers() ([]Gopher, error) | |
GetGopher(id string) (Gopher, 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
func main() { | |
// Create the Gopher Repository | |
gopherService := gopher.NewService(gopher.NewMemoryRepository()) | |
// We create yet another Fields map, one which holds all the different queries | |
fields := graphql.Fields{ | |
// We define the Gophers query | |
"gophers": &graphql.Field{ | |
// It will return a list of GopherTypes, a List is an Slice | |
// We defined our Type in the Schemas package earlier | |
Type: graphql.NewList(schemas.GopherType), |
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
// GopherService is the service that holds all repositories | |
type GopherService struct { | |
gophers Repository | |
} | |
// NewService is a factory that creates a new GopherService | |
func NewService(repo Repository) GopherService { | |
return GopherService{ | |
gophers: repo, | |
} |
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
// InMemoryRepository is a storage for gophers that uses a map to store them | |
type InMemoryRepository struct { | |
// gophers is our super storage for gophers. | |
gophers []Gopher | |
sync.Mutex | |
} | |
// NewMemoryRepository initializes a memory with mock data | |
func NewMemoryRepository() *InMemoryRepository { | |
gophers := []Gopher{ |
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
import './App.css' | |
function() App { | |
return ( | |
<div className="app"> | |
</div> | |
); | |
} | |
export default App; |
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
// Load the static webpage with a File Server | |
webapp := http.FileServer(http.Dir("ui/pingpongapp/build")) |
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 | |
// Has to conform to the schema declaration | |
type Gopher struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
Hired bool `json:"hired"` | |
Profession string `json:"profession"` | |
} |