1
Fork 0

Start on graphql in go

This commit is contained in:
viktorstrate 2020-01-30 14:28:14 +01:00
parent 9c59e69a66
commit 9d95b7bead
9 changed files with 3273 additions and 0 deletions

8
api/go.mod Normal file
View File

@ -0,0 +1,8 @@
module github.com/viktorstrate/photoview/api
go 1.13
require (
github.com/99designs/gqlgen v0.10.2
github.com/vektah/gqlparser v1.2.0
)

51
api/go.sum Normal file
View File

@ -0,0 +1,51 @@
github.com/99designs/gqlgen v0.10.2 h1:FfjCqIWejHDJeLpQTI0neoZo5vDO3sdo5oNCucet3A0=
github.com/99designs/gqlgen v0.10.2/go.mod h1:aDB7oabSAyZ4kUHLEySsLxnWrBy3lA0A2gWKU+qoHwI=
github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
github.com/vektah/gqlparser v1.2.0 h1:ntkSCX7F5ZJKl+HIVnmLaO269MruasVpNiMOjX9kgo0=
github.com/vektah/gqlparser v1.2.0/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
github.com/viktorstrate/photoview v0.0.0-20200119220544-691e4c7dc433 h1:n6jGnDctC9HI7B1rnc5ATQPYaaxQaJtS8bI6oI0QV34=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd h1:oMEQDWVXVNpceQoVd1JN3CQ7LYJJzs5qWqZIUcxXHHw=
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k=

18
api/gqlgen.yml Normal file
View File

@ -0,0 +1,18 @@
# .gqlgen.yml example
#
# Refer to https://gqlgen.com/config/
# for detailed .gqlgen.yml documentation.
schema:
- graphql/schema.graphql
exec:
filename: graphql/generated.go
model:
filename: graphql/models_gen.go
resolver:
filename: graphql/resolver.go
type: Resolver
autobind: []
# models:
# Todo:
# model: github.com/viktorstrate/photoview/api.Todo

2937
api/graphql/generated.go Normal file

File diff suppressed because it is too large Load Diff

16
api/graphql/models_gen.go Normal file
View File

@ -0,0 +1,16 @@
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package api
type AuthorizeResult struct {
Success bool `json:"success"`
Status string `json:"status"`
Token *string `json:"token"`
}
type User struct {
ID string `json:"id"`
Username string `json:"username"`
RootPath string `json:"rootPath"`
Admin bool `json:"admin"`
}

31
api/graphql/resolver.go Normal file
View File

@ -0,0 +1,31 @@
package api
import (
"context"
) // THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.
type Resolver struct{}
func (r *Resolver) Mutation() MutationResolver {
return &mutationResolver{r}
}
func (r *Resolver) Query() QueryResolver {
return &queryResolver{r}
}
type mutationResolver struct{ *Resolver }
func (r *mutationResolver) AuthorizeUser(ctx context.Context, username string, password string) (*AuthorizeResult, error) {
panic("not implemented")
}
func (r *mutationResolver) RegisterUser(ctx context.Context, username string, password string) (*AuthorizeResult, error) {
panic("not implemented")
}
type queryResolver struct{ *Resolver }
func (r *queryResolver) Users(ctx context.Context) ([]*User, error) {
users := make([]*User, 0)
return users, nil
}

View File

@ -0,0 +1,161 @@
scalar Time
enum Role {
admin
user
}
type User {
id: ID!
username: String!
albums: [Album]
# Local filepath for the user's photos
rootPath: String!
admin: Boolean
shareTokens: [ShareToken]
}
type Album {
id: ID!
title: String
photos: [Photo]
subAlbums: [Album]
parentAlbum: Album
owner: User!
path: String
shares: [ShareToken]
}
type PhotoURL {
# URL for previewing the image
url: String
# Width of the image in pixels
width: Int
# Height of the image in pixels
height: Int
}
type PhotoDownload {
title: String
url: String
}
type PhotoEXIF {
photo: Photo
camera: String
maker: String
lens: String
dateShot: Time
fileSize: String
exposure: String
aperture: Float
iso: Int
focalLength: String
flash: String
}
type Photo {
id: ID!
title: String
# Local filepath for the photo
path: String
# URL to display the photo in full resolution
original: PhotoURL
# URL to display the photo in a smaller resolution
thumbnail: PhotoURL
# The album that holds the photo
album: Album!
exif: PhotoEXIF
shares: [ShareToken]
downloads: [PhotoDownload]
}
type ShareToken {
token: ID!
owner: User
# Optional expire date
expire: Time
# Optional password
# password: String
album: Album
photo: Photo
}
type SiteInfo {
initialSetup: Boolean!
}
type AuthorizeResult {
success: Boolean!
status: String
token: String
}
type ScannerResult {
finished: Boolean!
success: Boolean!
progress: Float
message: String
}
type Result {
success: Boolean!
errorMessage: String
}
type Subscription {
scannerStatusUpdate: ScannerResult
}
type Mutation {
authorizeUser(username: String!, password: String!): AuthorizeResult!
registerUser(
username: String!
password: String!
rootPath: String!
): AuthorizeResult!
shareAlbum(albumId: ID!, expire: Time, password: String): ShareToken
sharePhoto(photoId: ID!, expire: Time, password: String): ShareToken
deleteShareToken(token: ID!): ShareToken
setAdmin(userId: ID!, admin: Boolean!): Result!
scanAll: ScannerResult!
scanUser(userId: ID!): ScannerResult!
initialSetupWizard(
username: String!
password: String!
rootPath: String!
): AuthorizeResult
updateUser(id: ID!, username: String, rootPath: String, admin: Boolean): User
createUser(id: ID, username: String, rootPath: String, admin: Boolean): User
deleteUser(id: ID!): User
changeUserPassword(id: ID!, newPassword: String!): Result
}
type Query {
siteInfo: SiteInfo
myUser: User
user: [User]
myAlbums: [Album]
album(id: ID): Album
myPhotos: [Photo]
photo(id: ID!): Photo
shareToken(token: ID!): ShareToken
albumShares(id: ID!, password: String): [ShareToken]
photoShares(id: ID!, password: String): [ShareToken]
}

View File

@ -0,0 +1,26 @@
type Query {
users: [User!]!
}
type Mutation {
authorizeUser(username: String!, password: String!): AuthorizeResult!
# Add rootPath later
registerUser(username: String!, password: String!): AuthorizeResult!
}
type AuthorizeResult {
success: Boolean!
status: String!
token: String
}
type User {
id: ID!
username: String!
#albums: [Album]
# Local filepath for the user's photos
rootPath: String!
admin: Boolean!
#shareTokens: [ShareToken]
}

25
api/server/server.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/handler"
photoview_graphql "github.com/viktorstrate/photoview/api/graphql"
)
const defaultPort = "8080"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
http.Handle("/", handler.Playground("GraphQL playground", "/query"))
http.Handle("/query", handler.GraphQL(photoview_graphql.NewExecutableSchema(photoview_graphql.Config{Resolvers: &photoview_graphql.Resolver{}})))
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}