Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
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
// 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 {
@percybolmer
percybolmer / GraphQL-job.go
Last active September 10, 2021 09:43
graphql
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 {
package gopher
type Repository interface {
GetGophers() ([]Gopher, error)
GetGopher(id string) (Gopher, error)
}
@percybolmer
percybolmer / GraphQL-mainv2.go
Last active September 9, 2021 05:26
Graphql
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),
// 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,
}
// 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{
@percybolmer
percybolmer / gRPC-cleanReact.js
Created September 6, 2021 20:59
gRPC-multiplex
import './App.css'
function() App {
return (
<div className="app">
</div>
);
}
export default App;
// Load the static webpage with a File Server
webapp := http.FileServer(http.Dir("ui/pingpongapp/build"))
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"`
}