graphql

package module
v0.0.0-...-d87ace7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 35 Imported by: 3

README

graphql.natwelch.com

A new backend for graphql.natwelch.com.

Build Status Go Report Card Go Reference

The next iteration in Nat's content management system. Previous versions include:

Install

This repo requires Go 1.11 to be installed.

  1. Start postgres on your local machine with a database called writing.
  2. Copy local.env to .env
  3. env $(cat .env) go run -v ./server to start the server.
  4. Visit http://localhost:8080/ which has a default graphql client.
Example Env
DATABASE_URL=postgres://localhost/writing?sslmode=disable&binary_parameters=yes
SESSION_SECRET="random string"
OAUTH2_CLIENTID=something.apps.googleusercontent.com
OAUTH2_SECRET=1234567890
OAUTH2_REDIRECT=http://localhost:8080/callback
PORT=9393
Auth

This uses Auth0 to generate logins. To save yourself setting up the Auth0, you can generate an API key for testing by creating a user. To create a user for testing, run the following insert SQL:

INSERT INTO users (id, role, created_at, modified_at) VALUES ('test', 'admin', now(), now());

Then get your API key:

SELECT apikey from users where id = 'test';

And then set that as the value of the X-API-AUTH on all of your requests to graphql.

Design

This site is hosted at https://graphql.natwelch.com. It runs out of a docker container on Google Kubernetes. It has a postgres backend. This started as a rewrite of a previous project, natnatnat. Its readme walks through a lot of the previous inspiration.

We use https://github.com/99designs/gqlgen to generate a lot of the files.

Documentation

Documentation

Index

Constants

View Source
const (
	// AppName is the name of the service in GCP.
	AppName = "graphql"
)
View Source
const (
	// StorageBucketName is the bucket name we are uploading to.
	StorageBucketName = "icco-cloud"
)

Variables

View Source
var (
	// HashtagRegex is a regex for finding hashtags in Markdown.
	HashtagRegex = regexp.MustCompile(`(\s)#(\w+)`)

	// TwitterHandleRegex is a regex for finding @username in Markdown.
	TwitterHandleRegex = regexp.MustCompile(`(\s)@([_A-Za-z0-9]+)`)
)
View Source
var AllRole = []Role{
	RoleAdmin,
	RoleNormal,
}

Functions

func AllTags

func AllTags(ctx context.Context) ([]string, error)

AllTags returns all tags used in all posts.

func GeoConvertValue

func GeoConvertValue(v interface{}) (driver.Value, error)

GeoConvertValue is used for marshaling data to a database.

func GeoScanner

func GeoScanner(g interface{}) *wkb.GeometryScanner

GeoScanner is used for unmarshaling data from a database row.

func GetMaxID

func GetMaxID(ctx context.Context) (int64, error)

GetMaxID returns the greatest post ID in the database.

func InitDB

func InitDB(dataSourceName string) (*sql.DB, error)

InitDB creates a package global db connection from a database string.

func Markdown

func Markdown(str string) template.HTML

Markdown generator.

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

func ParseLimit

func ParseLimit(lim *Limit, defaultLimit, defaultOffset int) (int, int)

ParseLimit turns a limit and applies defaults into a pair of ints.

func ParseTags

func ParseTags(text string) ([]string, error)

ParseTags returns a list of all hashtags currently in a post.

func SummarizeText

func SummarizeText(str string) string

SummarizeText takes a chunk of markdown and just returns the first paragraph.

func WithUser

func WithUser(ctx context.Context, u *User) context.Context

WithUser puts a user in the context.

Types

type AddComment

type AddComment struct {
	Content string `json:"content"`
	PostID  string `json:"post_id"`
}

type Book

type Book struct {
	ID          string `json:"id"`
	GoodreadsID string
	Title       string `json:"title"`
	Link        string
	Authors     []string
	ISBN        string
	Created     time.Time `json:"created"`
	Modified    time.Time `json:"modified"`
}

Book is a book on Goodreads.

func GetBooks

func GetBooks(ctx context.Context, limit int, offset int) ([]*Book, error)

GetBooks returns all books from the database.

func (*Book) GetURI

func (b *Book) GetURI() URI

func (Book) IsLinkable

func (Book) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Book) Save

func (b *Book) Save(ctx context.Context) error

Save inserts or updates a book into the database.

func (*Book) URI

func (b *Book) URI() *URI

URI returns an absolute link to this book.

type Cache

type Cache struct {
}

Cache is a basic type as defined by gqlgen.

func NewCache

func NewCache() (*Cache, error)

NewCache creates a new cache.

func (*Cache) Add

func (c *Cache) Add(ctx context.Context, hash string, query interface{})

Add inserts a key value pair into the database.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, hash string) (interface{}, bool)

Get retrieves a value by a key.

type Comment

type Comment struct {
	ID       string    `json:"id"`
	Post     *Post     `json:"post"`
	User     *User     `json:"author"`
	Content  string    `json:"content"`
	Created  time.Time `json:"created"`
	Modified time.Time `json:"modified"`
}

Comment is a comment on a post.

func AllComments

func AllComments(ctx context.Context, limit int, offset int) ([]*Comment, error)

AllComments returns all comments orderd by time.

func GetComment

func GetComment(ctx context.Context, id string) (*Comment, error)

GetComment returns a single comment by ID.

func PostComments

func PostComments(ctx context.Context, p string, limit int, offset int) ([]*Comment, error)

PostComments returns comments for a post ID.

func (*Comment) GetURI

func (c *Comment) GetURI() URI

func (Comment) IsLinkable

func (Comment) IsLinkable()

IsLinkable tells gqlgen this model has a URI function.

func (*Comment) Save

func (c *Comment) Save(ctx context.Context) error

Save adds the comment to the database and checks that no data is missing.

func (*Comment) URI

func (c *Comment) URI() *URI

URI returns the URI for this comment.

type ComplexityRoot

type ComplexityRoot struct {
	Book struct {
		ID    func(childComplexity int) int
		Title func(childComplexity int) int
		URI   func(childComplexity int) int
	}

	Comment struct {
		Content  func(childComplexity int) int
		Created  func(childComplexity int) int
		ID       func(childComplexity int) int
		Modified func(childComplexity int) int
		Post     func(childComplexity int) int
		URI      func(childComplexity int) int
		User     func(childComplexity int) int
	}

	Geo struct {
		Lat  func(childComplexity int) int
		Long func(childComplexity int) int
	}

	Link struct {
		Created     func(childComplexity int) int
		Description func(childComplexity int) int
		ID          func(childComplexity int) int
		Modified    func(childComplexity int) int
		Screenshot  func(childComplexity int) int
		Tags        func(childComplexity int) int
		Title       func(childComplexity int) int
		URI         func(childComplexity int) int
	}

	Log struct {
		Created     func(childComplexity int) int
		Description func(childComplexity int) int
		Duration    func(childComplexity int) int
		ID          func(childComplexity int) int
		Modified    func(childComplexity int) int
		Project     func(childComplexity int) int
		Sector      func(childComplexity int) int
		Started     func(childComplexity int) int
		Stopped     func(childComplexity int) int
		URI         func(childComplexity int) int
		User        func(childComplexity int) int
	}

	Mutation struct {
		AddComment  func(childComplexity int, input AddComment) int
		CreatePost  func(childComplexity int, input EditPost) int
		EditPost    func(childComplexity int, input EditPost) int
		InsertLog   func(childComplexity int, input NewLog) int
		UpsertBook  func(childComplexity int, input EditBook) int
		UpsertLink  func(childComplexity int, input NewLink) int
		UpsertStat  func(childComplexity int, input NewStat) int
		UpsertTweet func(childComplexity int, input NewTweet) int
	}

	Photo struct {
		ContentType func(childComplexity int) int
		Created     func(childComplexity int) int
		ID          func(childComplexity int) int
		Modified    func(childComplexity int) int
		URI         func(childComplexity int) int
		Year        func(childComplexity int) int
	}

	Post struct {
		Comments    func(childComplexity int, input *Limit) int
		Content     func(childComplexity int) int
		Created     func(childComplexity int) int
		Datetime    func(childComplexity int) int
		Draft       func(childComplexity int) int
		ID          func(childComplexity int) int
		Links       func(childComplexity int) int
		Modified    func(childComplexity int) int
		Next        func(childComplexity int) int
		Prev        func(childComplexity int) int
		Readtime    func(childComplexity int) int
		Related     func(childComplexity int, input *Limit) int
		SocialImage func(childComplexity int) int
		Summary     func(childComplexity int) int
		Tags        func(childComplexity int) int
		Title       func(childComplexity int) int
		URI         func(childComplexity int) int
	}

	Query struct {
		Books              func(childComplexity int, input *Limit) int
		Comments           func(childComplexity int, input *Limit) int
		Counts             func(childComplexity int) int
		Drafts             func(childComplexity int, input *Limit) int
		FuturePosts        func(childComplexity int, input *Limit) int
		HomeTimelineURLs   func(childComplexity int, input *Limit) int
		Link               func(childComplexity int, id *string, url *URI) int
		Links              func(childComplexity int, input *Limit) int
		Log                func(childComplexity int, id string) int
		Logs               func(childComplexity int, input *Limit) int
		NextPost           func(childComplexity int, id string) int
		Photos             func(childComplexity int, input *Limit) int
		Post               func(childComplexity int, id string) int
		Posts              func(childComplexity int, input *Limit) int
		PostsByTag         func(childComplexity int, id string) int
		PrevPost           func(childComplexity int, id string) int
		Search             func(childComplexity int, query string, input *Limit) int
		Stat               func(childComplexity int, key string, input *Limit) int
		Stats              func(childComplexity int, count *int) int
		Tags               func(childComplexity int) int
		Time               func(childComplexity int) int
		Tweet              func(childComplexity int, id string) int
		Tweets             func(childComplexity int, input *Limit) int
		TweetsByScreenName func(childComplexity int, screenName string, input *Limit) int
		Whoami             func(childComplexity int) int
	}

	Stat struct {
		Key   func(childComplexity int) int
		Value func(childComplexity int) int
		When  func(childComplexity int) int
	}

	Tweet struct {
		FavoriteCount func(childComplexity int) int
		Hashtags      func(childComplexity int) int
		ID            func(childComplexity int) int
		Posted        func(childComplexity int) int
		RetweetCount  func(childComplexity int) int
		ScreenName    func(childComplexity int) int
		Symbols       func(childComplexity int) int
		Text          func(childComplexity int) int
		URI           func(childComplexity int) int
		Urls          func(childComplexity int) int
		UserMentions  func(childComplexity int) int
	}

	TwitterURL struct {
		CreatedAt  func(childComplexity int) int
		Link       func(childComplexity int) int
		ModifiedAt func(childComplexity int) int
		TweetIDs   func(childComplexity int) int
		Tweets     func(childComplexity int) int
		URI        func(childComplexity int) int
	}

	User struct {
		APIKey   func(childComplexity int) int
		Created  func(childComplexity int) int
		ID       func(childComplexity int) int
		Modified func(childComplexity int) int
		Name     func(childComplexity int) int
		Role     func(childComplexity int) int
	}
}

type Config

type Config struct {
	Schema     *ast.Schema
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

func New

func New() Config

New returns a Config that has all of the proper settings for this graphql server.

type DirectiveRoot

type DirectiveRoot struct {
	HasRole  func(ctx context.Context, obj interface{}, next graphql.Resolver, role Role) (res interface{}, err error)
	LoggedIn func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error)
}

type Duration

type Duration struct {
	// contains filtered or unexported fields
}

Duration is a float64 representation of a Duration in seconds.

func NewDuration

func NewDuration(raw float64) Duration

NewDuration creates a new Duration.

func ParseDurationFromDuration

func ParseDurationFromDuration(dur time.Duration) Duration

ParseDurationFromDuration takes a stdlib Duration and turns it into our duration.

func ParseDurationFromString

func ParseDurationFromString(dur string) Duration

ParseDurationFromString takes a duration string and turns it into a duration. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

func (Duration) MarshalGQL

func (d Duration) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON turns a duration to a string.

func (*Duration) Scan

func (d *Duration) Scan(v interface{}) error

Scan implements the driver.Scan interface

func (*Duration) UnmarshalGQL

func (d *Duration) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Marshaler interface

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(value []byte) error

UnmarshalJSON turns a string to a Duration.

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

Value implements the driver.Value interface.

type EditBook

type EditBook struct {
	ID          *string `json:"id,omitempty"`
	Title       *string `json:"title,omitempty"`
	GoodreadsID string  `json:"goodreads_id"`
}

type EditPost

type EditPost struct {
	ID       *string    `json:"id,omitempty"`
	Content  *string    `json:"content,omitempty"`
	Title    *string    `json:"title,omitempty"`
	Datetime *time.Time `json:"datetime,omitempty"`
	Draft    *bool      `json:"draft,omitempty"`
}

type Geo

type Geo struct {
	Lat  float64 `json:"lat"`
	Long float64 `json:"long"`
}

Geo is a simple type for wrapping a point. Units are in Degrees.

func GeoFromOrb

func GeoFromOrb(p *orb.Point) *Geo

GeoFromOrb creates a Geo from github.com/paulmach/orb.Point.

func (*Geo) ToOrb

func (g *Geo) ToOrb() orb.Point

ToOrb translates a Geo point into one that has lots of useful functions on it.

type InputGeo

type InputGeo struct {
	Lat  float64 `json:"lat"`
	Long float64 `json:"long"`
}

type Limit

type Limit struct {
	Limit  *int `json:"limit,omitempty"`
	Offset *int `json:"offset,omitempty"`
}
type Link struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	URI         URI       `json:"uri"`
	Created     time.Time `json:"created"`
	Description string    `json:"description"`
	Screenshot  URI       `json:"screenshot"`
	Tags        []string  `json:"tags"`
	Modified    time.Time `json:"modified"`
}

Link is a link I have save on pinboard or a link in a post.

func GetLinkByID

func GetLinkByID(ctx context.Context, id string) (*Link, error)

GetLinkByID gets a link by id from the database.

func GetLinkByURI

func GetLinkByURI(ctx context.Context, uri string) (*Link, error)

GetLinkByURI gets a link by uri from the database.

func GetLinks(ctx context.Context, limit int, offset int) ([]*Link, error)

GetLinks returns all links from the database.

func (*Link) GetURI

func (l *Link) GetURI() URI

func (*Link) IsLinkable

func (l *Link) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Link) Save

func (l *Link) Save(ctx context.Context) error

Save inserts or updates a link into the database.

type Linkable

type Linkable interface {
	IsLinkable()
	GetURI() URI
}

type Log

type Log struct {
	ID          string    `json:"id"`
	Sector      Sector    `json:"sector"`
	Description string    `json:"description"`
	Project     string    `json:"project"`
	User        User      `json:"user"`
	Started     time.Time `json:"started"`
	Stopped     time.Time `json:"stopped"`
	Created     time.Time `json:"created"`
	Modified    time.Time `json:"modified"`
}

A Log is a journal entry by an individual.

func GetLog

func GetLog(ctx context.Context, id string) (*Log, error)

GetLog gets a single Log by ID.

func UserLogs

func UserLogs(ctx context.Context, u *User, limit int, offset int) ([]*Log, error)

UserLogs gets all logs for a User.

func (*Log) Duration

func (l *Log) Duration() (Duration, error)

func (*Log) GetURI

func (l *Log) GetURI() URI

func (*Log) IsLinkable

func (l *Log) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Log) Save

func (l *Log) Save(ctx context.Context) error

Save inserts or updates a log into the database.

func (*Log) SetUser

func (l *Log) SetUser(ctx context.Context, id string) error

SetUser looks up a user by ID and then sets it for this log.

func (*Log) URI

func (l *Log) URI() *URI

URI returns the URI for this log.

type MutationResolver

type MutationResolver interface {
	UpsertBook(ctx context.Context, input EditBook) (*Book, error)
	UpsertLink(ctx context.Context, input NewLink) (*Link, error)
	UpsertStat(ctx context.Context, input NewStat) (*Stat, error)
	UpsertTweet(ctx context.Context, input NewTweet) (*Tweet, error)
	AddComment(ctx context.Context, input AddComment) (*Comment, error)
	CreatePost(ctx context.Context, input EditPost) (*Post, error)
	EditPost(ctx context.Context, input EditPost) (*Post, error)
	InsertLog(ctx context.Context, input NewLog) (*Log, error)
}
type NewLink struct {
	Title       string     `json:"title"`
	URI         URI        `json:"uri"`
	Description string     `json:"description"`
	Tags        []string   `json:"tags"`
	Created     *time.Time `json:"created,omitempty"`
}

type NewLog

type NewLog struct {
	Sector      Sector    `json:"sector"`
	Description *string   `json:"description,omitempty"`
	Project     string    `json:"project"`
	Started     time.Time `json:"started"`
	Stopped     time.Time `json:"stopped"`
}

type NewStat

type NewStat struct {
	Key   string  `json:"key"`
	Value float64 `json:"value"`
}

type NewTweet

type NewTweet struct {
	FavoriteCount int       `json:"favorite_count"`
	Hashtags      []string  `json:"hashtags,omitempty"`
	ID            string    `json:"id"`
	Posted        time.Time `json:"posted"`
	RetweetCount  int       `json:"retweet_count"`
	Symbols       []string  `json:"symbols,omitempty"`
	Text          string    `json:"text"`
	Urls          []*URI    `json:"urls,omitempty"`
	ScreenName    string    `json:"screen_name"`
	UserMentions  []string  `json:"user_mentions,omitempty"`
}

type Photo

type Photo struct {
	ID          string `json:"id"`
	User        User   `json:"user"`
	Year        int
	ContentType string
	Created     time.Time `json:"created"`
	Modified    time.Time `json:"modified"`
}

Photo represents an uploaded photo

func UserPhotos

func UserPhotos(ctx context.Context, u *User, limit int, offset int) ([]*Photo, error)

UserPhotos gets all photos for a User.

func (*Photo) GetURI

func (p *Photo) GetURI() URI

func (*Photo) IsLinkable

func (p *Photo) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Photo) Path

func (p *Photo) Path() string

Path returns the path the photo should be saved to.

func (*Photo) Save

func (p *Photo) Save(ctx context.Context) error

Save adds the photo to the database and checks that no data is missing.

func (*Photo) URI

func (p *Photo) URI() *URI

URI returns the URI for this photo.

func (*Photo) Upload

func (p *Photo) Upload(ctx context.Context, f io.Reader) error

Upload save the photo to GCS, and also makes sure the record is saved to the database.

type Post

type Post struct {
	ID       string    `json:"id"`
	Title    string    `json:"title"`
	Content  string    `json:"content"`
	Datetime time.Time `json:"datetime"`
	Created  time.Time `json:"created"`
	Modified time.Time `json:"modified"`
	Draft    bool      `json:"draft"`
	Tags     []string  `json:"tags"`
	Links    []*Link   `json:"links"`
}

Post is our representation of a post in the database.

func Drafts

func Drafts(ctx context.Context, limit, offset int) ([]*Post, error)

Drafts is a simple wrapper around Posts that does return drafts.

func FuturePosts

func FuturePosts(ctx context.Context, limit int, offset int) ([]*Post, error)

FuturePosts returns some posts that are in the future.

func GetPost

func GetPost(ctx context.Context, id int64) (*Post, error)

GetPost gets a post by ID from the database.

func GetPostString

func GetPostString(ctx context.Context, id string) (*Post, error)

GetPostString gets a post by an ID string.

func GetRandomPosts

func GetRandomPosts(ctx context.Context, limit int, notIn []int64) ([]*Post, error)

GetRandomPosts returns a random selection of posts.

func Posts

func Posts(ctx context.Context, limit int, offset int) ([]*Post, error)

Posts returns some posts.

func PostsByTag

func PostsByTag(ctx context.Context, tag string) ([]*Post, error)

PostsByTag returns all posts with a tag.

func Search(ctx context.Context, searchQuery string, limit int, offset int) ([]*Post, error)

Search searches for posts that have matching titles, content or tags

func (*Post) Comments

func (p *Post) Comments(ctx context.Context, input *Limit) ([]*Comment, error)

Comments returns the comments for a post

func (*Post) GetURI

func (p *Post) GetURI() URI

func (*Post) HTML

func (p *Post) HTML() template.HTML

HTML returns the post as rendered HTML.

func (*Post) IntID

func (p *Post) IntID() int64

IntID returns this posts ID as an int.

func (*Post) IsLinkable

func (p *Post) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Post) Next

func (p *Post) Next(ctx context.Context) (*Post, error)

Next returns the next post chronologically.

func (*Post) Prev

func (p *Post) Prev(ctx context.Context) (*Post, error)

Prev returns the previous post chronologically.

func (*Post) Readtime

func (p *Post) Readtime(_ context.Context) int32

ReadTime calculates the number of seconds it should take to read the post.

func (*Post) Related

func (p *Post) Related(ctx context.Context, input *Limit) ([]*Post, error)

Related returns an array of related posts. It is quite slow in comparison to other queries.

func (*Post) Save

func (p *Post) Save(ctx context.Context) error

Save inserts or updates a post into the database.

func (*Post) SocialImage

func (p *Post) SocialImage(ctx context.Context) (*URI, error)

func (*Post) Summary

func (p *Post) Summary() string

Summary returns the first sentence of a post.

func (*Post) URI

func (p *Post) URI() *URI

URI returns an absolute link to this post.

type QueryResolver

type QueryResolver interface {
	Books(ctx context.Context, input *Limit) ([]*Book, error)
	Links(ctx context.Context, input *Limit) ([]*Link, error)
	Link(ctx context.Context, id *string, url *URI) (*Link, error)
	Stats(ctx context.Context, count *int) ([]*Stat, error)
	Stat(ctx context.Context, key string, input *Limit) ([]*Stat, error)
	Counts(ctx context.Context) ([]*Stat, error)
	Whoami(ctx context.Context) (*User, error)
	Tweets(ctx context.Context, input *Limit) ([]*Tweet, error)
	Tweet(ctx context.Context, id string) (*Tweet, error)
	TweetsByScreenName(ctx context.Context, screenName string, input *Limit) ([]*Tweet, error)
	HomeTimelineURLs(ctx context.Context, input *Limit) ([]*TwitterURL, error)
	Time(ctx context.Context) (*time.Time, error)
	Drafts(ctx context.Context, input *Limit) ([]*Post, error)
	FuturePosts(ctx context.Context, input *Limit) ([]*Post, error)
	Posts(ctx context.Context, input *Limit) ([]*Post, error)
	Comments(ctx context.Context, input *Limit) ([]*Comment, error)
	Search(ctx context.Context, query string, input *Limit) ([]*Post, error)
	Post(ctx context.Context, id string) (*Post, error)
	NextPost(ctx context.Context, id string) (*Post, error)
	PrevPost(ctx context.Context, id string) (*Post, error)
	PostsByTag(ctx context.Context, id string) ([]*Post, error)
	Tags(ctx context.Context) ([]string, error)
	Logs(ctx context.Context, input *Limit) ([]*Log, error)
	Log(ctx context.Context, id string) (*Log, error)
	Photos(ctx context.Context, input *Limit) ([]*Photo, error)
}

type Resolver

type Resolver struct{}

Resolver is the type that gqlgen expects to exist

func (*Resolver) Mutation

func (r *Resolver) Mutation() MutationResolver

Mutation returns MutationResolver implementation.

func (*Resolver) Query

func (r *Resolver) Query() QueryResolver

Query returns QueryResolver implementation.

type ResolverRoot

type ResolverRoot interface {
	Mutation() MutationResolver
	Query() QueryResolver
}

type Role

type Role string
const (
	RoleAdmin  Role = "admin"
	RoleNormal Role = "normal"
)

func (Role) IsValid

func (e Role) IsValid() bool

func (Role) MarshalGQL

func (e Role) MarshalGQL(w io.Writer)

func (Role) String

func (e Role) String() string

func (*Role) UnmarshalGQL

func (e *Role) UnmarshalGQL(v interface{}) error

type Searchable

type Searchable interface {
	IsSearchable()
	GetSummary() string
}

type Sector

type Sector string
const (
	SectorCode     Sector = "CODE"
	SectorWriting  Sector = "WRITING"
	SectorAudio    Sector = "AUDIO"
	SectorResearch Sector = "RESEARCH"
	SectorSocial   Sector = "SOCIAL"
	SectorPersonal Sector = "PERSONAL"
)

func (Sector) IsValid

func (e Sector) IsValid() bool

func (Sector) MarshalGQL

func (e Sector) MarshalGQL(w io.Writer)

func (Sector) String

func (e Sector) String() string

func (*Sector) UnmarshalGQL

func (e *Sector) UnmarshalGQL(v interface{}) error

type Stat

type Stat struct {
	Key   string    `json:"key"`
	Value float64   `json:"value"`
	When  time.Time `json:"when"`
}

A stat is a key value pair of two interesting strings.

func GetStat

func GetStat(ctx context.Context, key string, limit int, offset int) ([]*Stat, error)

GetStat returns the history of a stat

func GetStats

func GetStats(ctx context.Context, limit int) ([]*Stat, error)

GetStats returns the limit of the most recently updated stats.

func (*Stat) Save

func (s *Stat) Save(ctx context.Context) error

Save upserts a stat.

type Tweet

type Tweet struct {
	ID            string    `json:"id"`
	Text          string    `json:"text"`
	Hashtags      []string  `json:"hashtags"`
	Symbols       []string  `json:"symbols"`
	UserMentions  []string  `json:"user_mentions"`
	Urls          []*URI    `json:"urls"`
	ScreenName    string    `json:"screen_name"`
	FavoriteCount int       `json:"favorite_count"`
	RetweetCount  int       `json:"retweet_count"`
	Posted        time.Time `json:"posted"`
}

A Tweet is an archived tweet.

func GetTweet

func GetTweet(ctx context.Context, id string) (*Tweet, error)

GetTweet returns a single tweet by id.

func GetTweets

func GetTweets(ctx context.Context, limit, offset int) ([]*Tweet, error)

GetTweets returns an array of tweets from the database.

func GetTweetsByScreenName

func GetTweetsByScreenName(ctx context.Context, screenName string, limit, offset int) ([]*Tweet, error)

GetTweetsByScreenName returns an array of tweets from the database filtered by screenname.

func (*Tweet) GetURI

func (t *Tweet) GetURI() URI

func (*Tweet) IsLinkable

func (t *Tweet) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*Tweet) Save

func (t *Tweet) Save(ctx context.Context) error

Save inserts or updates a tweet into the database.

func (*Tweet) URI

func (t *Tweet) URI() *URI

URI returns a link to this tweet.

type TwitterURL

type TwitterURL struct {
	Link       *URI
	TweetIDs   []string
	CreatedAt  time.Time
	ModifiedAt time.Time
}

TwitterURL is a representation of data from cacophony.

func (*TwitterURL) GetURI

func (tu *TwitterURL) GetURI() URI

func (*TwitterURL) IsLinkable

func (tu *TwitterURL) IsLinkable()

IsLinkable exists to show that this method implements the Linkable type in graphql.

func (*TwitterURL) Tweets

func (tu *TwitterURL) Tweets(ctx context.Context) ([]*Tweet, error)

Tweets returns an array of tweets.

func (*TwitterURL) URI

func (tu *TwitterURL) URI() *URI

URI returns a link to this tweet.

type URI

type URI struct {
	// contains filtered or unexported fields
}

URI is a string representation of a URI. TODO: Turn into an actual URI.

func GenerateSocialImage

func GenerateSocialImage(ctx context.Context, title string, when time.Time) (*URI, error)

GenerateSocialImage creates a static image URL for a post.

func NewURI

func NewURI(raw string) *URI

NewURI creates a URI from a string.

func (URI) MarshalGQL

func (u URI) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (URI) MarshalJSON

func (u URI) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json interface.

func (*URI) Scan

func (u *URI) Scan(v interface{}) error

Scan implements the driver.Scan interface

func (*URI) String

func (u *URI) String() string

String returns the value

func (*URI) UnmarshalGQL

func (u *URI) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Marshaler interface

func (*URI) UnmarshalJSON

func (u *URI) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the encoding/json interface.

func (URI) Value

func (u URI) Value() (driver.Value, error)

Value implements the driver.Value interface

type User

type User struct {
	ID       string
	Name     string
	Role     string
	APIKey   string
	Created  time.Time
	Modified time.Time
}

User is a database object based off of what we get back from Google OAuth.

func GetUser

func GetUser(ctx context.Context, id string) (*User, error)

GetUser returns a user from the database. If the User does not exist, we create it.

func GetUserByAPIKey

func GetUserByAPIKey(ctx context.Context, apikey string) (*User, error)

GetUserByAPIKey returns a user from the database.

func GetUserFromContext

func GetUserFromContext(ctx context.Context) *User

GetUserFromContext finds the user from the context. This is usually inserted by WithUser.

func (User) Empty

func (u User) Empty() bool

Empty tells us if the user is real.

func (*User) Save

func (u *User) Save(ctx context.Context) error

Save is an upsert based operation for User.

Directories

Path Synopsis
time module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL