Verified Commit d0f9f0a4 authored by Daniel Sonck's avatar Daniel Sonck
Browse files

Update GraphQL to use new CueTrack

parent db6d825f
Pipeline #75 passed with stage
in 19 minutes and 43 seconds
# Federation forward declarations, not to be included but for IDE support
type CueTrack {}
scalar _FieldSet
directive @external on FIELD_DEFINITION
......
......@@ -2,15 +2,6 @@ stages:
- build
- deploy
before_script:
- eval $(ssh-agent -s | tee ssh-agent.env)
- chmod go-rwx $SSH_PRIVATE_KEY
- ssh-add $SSH_PRIVATE_KEY
after_script:
- . ssh-agent.env
- kill $SSH_AGENT_PID
build:
stage: build
script:
......@@ -22,13 +13,24 @@ build:
junit: target/reports/tests.xml
cobertura: target/reports/cobertura.xml
deploy:
before_script:
- eval $(ssh-agent -s | tee ssh-agent.env)
- chmod go-rwx $SSH_PRIVATE_KEY
- ssh-add $SSH_PRIVATE_KEY
after_script:
- . ssh-agent.env
- kill $SSH_AGENT_PID
stage: deploy
rules:
- if: '$CI_COMMIT_TAG =~ /^release\//'
script:
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_NAME"
- git clone ssh://gitlab@git.touhou.fm:7222/touhou.fm/radio-go/infra/radio.git
- cd radio
- git checkout ci/update-version
- cp ../playlist.version.auto.tfvars radio
- cp ../playlist.version.auto.tfvars ./
- git commit -a -m "Update version"
- git push -u origin ci/update-version -f
\ No newline at end of file
exec >&2
mkdir -p "$(dirname "$2")"
case $2 in
*/clover)
*/cobertura)
redo-ifchange "target/reports/coverage.txt" "tool/go-cobertura"
tool/go-cobertura -f target/reports/coverage.txt -o "$3"
tool/go-cobertura < "target/reports/coverage.txt" > "$3"
;;
*/tests)
redo-ifchange "target/reports/tests.txt" "tool/go-junit-report"
......
type PlayListItem @key(fields: "file start stop") {
type PlayListItem {
id: Int!
file: String!
start: Int64!
stop: Int64!
track: CueTrack!
}
extend type CueTrack @key(fields: "start stop file") {
start: Int64! @external
stop: Int64! @external
file: String! @external
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ package generated
import (
"context"
"errors"
"fmt"
"strings"
"github.com/99designs/gqlgen/plugin/federation/fedruntime"
......@@ -39,28 +38,6 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati
}
switch typeName {
case "PlayListItem":
id0, err := ec.unmarshalNString2string(ctx, rep["file"])
if err != nil {
return nil, errors.New(fmt.Sprintf("Field %s undefined in schema.", "file"))
}
id1, err := ec.unmarshalNInt642int64(ctx, rep["start"])
if err != nil {
return nil, errors.New(fmt.Sprintf("Field %s undefined in schema.", "start"))
}
id2, err := ec.unmarshalNInt642int64(ctx, rep["stop"])
if err != nil {
return nil, errors.New(fmt.Sprintf("Field %s undefined in schema.", "stop"))
}
entity, err := ec.resolvers.Entity().FindPlayListItemByFileAndStartAndStop(ctx,
id0, id1, id2)
if err != nil {
return nil, err
}
list = append(list, entity)
default:
return nil, errors.New("unknown type: " + typeName)
}
......
......@@ -37,7 +37,7 @@ type Config struct {
}
type ResolverRoot interface {
Entity() EntityResolver
PlayListItem() PlayListItemResolver
Query() QueryResolver
}
......@@ -45,15 +45,15 @@ type DirectiveRoot struct {
}
type ComplexityRoot struct {
Entity struct {
FindPlayListItemByFileAndStartAndStop func(childComplexity int, file string, start int64, stop int64) int
CueTrack struct {
File func(childComplexity int) int
Start func(childComplexity int) int
Stop func(childComplexity int) int
}
PlayListItem struct {
File func(childComplexity int) int
Id func(childComplexity int) int
Start func(childComplexity int) int
Stop func(childComplexity int) int
Track func(childComplexity int) int
}
Query struct {
......@@ -68,8 +68,8 @@ type ComplexityRoot struct {
}
}
type EntityResolver interface {
FindPlayListItemByFileAndStartAndStop(ctx context.Context, file string, start int64, stop int64) (*model.PlayListItem, error)
type PlayListItemResolver interface {
Track(ctx context.Context, obj *model.PlayListItem) (*model.CueTrack, error)
}
type QueryResolver interface {
PlaylistVersion(ctx context.Context) (string, error)
......@@ -91,24 +91,26 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
_ = ec
switch typeName + "." + field {
case "Entity.findPlayListItemByFileAndStartAndStop":
if e.complexity.Entity.FindPlayListItemByFileAndStartAndStop == nil {
case "CueTrack.file":
if e.complexity.CueTrack.File == nil {
break
}
args, err := ec.field_Entity_findPlayListItemByFileAndStartAndStop_args(context.TODO(), rawArgs)
if err != nil {
return 0, false
return e.complexity.CueTrack.File(childComplexity), true
case "CueTrack.start":
if e.complexity.CueTrack.Start == nil {
break
}
return e.complexity.Entity.FindPlayListItemByFileAndStartAndStop(childComplexity, args["file"].(string), args["start"].(int64), args["stop"].(int64)), true
return e.complexity.CueTrack.Start(childComplexity), true
case "PlayListItem.file":
if e.complexity.PlayListItem.File == nil {
case "CueTrack.stop":
if e.complexity.CueTrack.Stop == nil {
break
}
return e.complexity.PlayListItem.File(childComplexity), true
return e.complexity.CueTrack.Stop(childComplexity), true
case "PlayListItem.id":
if e.complexity.PlayListItem.Id == nil {
......@@ -117,19 +119,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.PlayListItem.Id(childComplexity), true
case "PlayListItem.start":
if e.complexity.PlayListItem.Start == nil {
break
}
return e.complexity.PlayListItem.Start(childComplexity), true
case "PlayListItem.stop":
if e.complexity.PlayListItem.Stop == nil {
case "PlayListItem.track":
if e.complexity.PlayListItem.Track == nil {
break
}
return e.complexity.PlayListItem.Stop(childComplexity), true
return e.complexity.PlayListItem.Track(childComplexity), true
case "Query.playlist":
if e.complexity.Query.Playlist == nil {
......@@ -224,12 +219,16 @@ var sources = []*ast.Source{
{Name: "graphql/playlist/query.graphqls", Input: `extend type Query {
playlist: [PlayListItem!]!
}`, BuiltIn: false},
{Name: "graphql/playlist/types.graphqls", Input: `type PlayListItem @key(fields: "file start stop") {
{Name: "graphql/playlist/types.graphqls", Input: `type PlayListItem {
id: Int!
file: String!
start: Int64!
stop: Int64!
track: CueTrack!
}
extend type CueTrack @key(fields: "start stop file") {
start: Int64! @external
stop: Int64! @external
file: String! @external
}`, BuiltIn: false},
{Name: "graphql/query.graphqls", Input: `type Query {
playlistVersion: String!
......@@ -247,13 +246,7 @@ directive @extends on OBJECT
`, BuiltIn: true},
{Name: "federation/entity.graphql", Input: `
# a union of all types that use the @key directive
union _Entity = PlayListItem
# fake type to build resolver interfaces for users to implement
type Entity {
findPlayListItemByFileAndStartAndStop(file: String!,start: Int64!,stop: Int64!,): PlayListItem!
}
union _Entity = CueTrack
type _Service {
sdl: String
......@@ -271,39 +264,6 @@ var parsedSchema = gqlparser.MustLoadSchema(sources...)
// region ***************************** args.gotpl *****************************
func (ec *executionContext) field_Entity_findPlayListItemByFileAndStartAndStop_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
var arg0 string
if tmp, ok := rawArgs["file"]; ok {
ctx := graphql.WithFieldInputContext(ctx, graphql.NewFieldInputWithField("file"))
arg0, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil {
return nil, err
}
}
args["file"] = arg0
var arg1 int64
if tmp, ok := rawArgs["start"]; ok {
ctx := graphql.WithFieldInputContext(ctx, graphql.NewFieldInputWithField("start"))
arg1, err = ec.unmarshalNInt642int64(ctx, tmp)
if err != nil {
return nil, err
}
}
args["start"] = arg1
var arg2 int64
if tmp, ok := rawArgs["stop"]; ok {
ctx := graphql.WithFieldInputContext(ctx, graphql.NewFieldInputWithField("stop"))
arg2, err = ec.unmarshalNInt642int64(ctx, tmp)
if err != nil {
return nil, err
}
}
args["stop"] = arg2
return args, nil
}
func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
......@@ -372,7 +332,7 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg
// region **************************** field.gotpl *****************************
func (ec *executionContext) _Entity_findPlayListItemByFileAndStartAndStop(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
func (ec *executionContext) _CueTrack_start(ctx context.Context, field graphql.CollectedField, obj *model.CueTrack) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
......@@ -380,23 +340,16 @@ func (ec *executionContext) _Entity_findPlayListItemByFileAndStartAndStop(ctx co
}
}()
fc := &graphql.FieldContext{
Object: "Entity",
Object: "CueTrack",
Field: field,
Args: nil,
IsMethod: true,
IsMethod: false,
}
ctx = graphql.WithFieldContext(ctx, fc)
rawArgs := field.ArgumentMap(ec.Variables)
args, err := ec.field_Entity_findPlayListItemByFileAndStartAndStop_args(ctx, rawArgs)
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
fc.Args = args
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Entity().FindPlayListItemByFileAndStartAndStop(rctx, args["file"].(string), args["start"].(int64), args["stop"].(int64))
return obj.Start, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -408,12 +361,12 @@ func (ec *executionContext) _Entity_findPlayListItemByFileAndStartAndStop(ctx co
}
return graphql.Null
}
res := resTmp.(*model.PlayListItem)
res := resTmp.(int64)
fc.Result = res
return ec.marshalNPlayListItem2ᚖgoᚗtouhouᚗfmᚋradioᚋserverᚋplaylistᚋinternalᚋgraphqlᚋmodelᚐPlayListItem(ctx, field.Selections, res)
return ec.marshalNInt642int64(ctx, field.Selections, res)
}
func (ec *executionContext) _PlayListItem_id(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
func (ec *executionContext) _CueTrack_stop(ctx context.Context, field graphql.CollectedField, obj *model.CueTrack) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
......@@ -421,7 +374,7 @@ func (ec *executionContext) _PlayListItem_id(ctx context.Context, field graphql.
}
}()
fc := &graphql.FieldContext{
Object: "PlayListItem",
Object: "CueTrack",
Field: field,
Args: nil,
IsMethod: false,
......@@ -430,7 +383,7 @@ func (ec *executionContext) _PlayListItem_id(ctx context.Context, field graphql.
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Id, nil
return obj.Stop, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -442,12 +395,12 @@ func (ec *executionContext) _PlayListItem_id(ctx context.Context, field graphql.
}
return graphql.Null
}
res := resTmp.(int)
res := resTmp.(int64)
fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res)
return ec.marshalNInt642int64(ctx, field.Selections, res)
}
func (ec *executionContext) _PlayListItem_file(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
func (ec *executionContext) _CueTrack_file(ctx context.Context, field graphql.CollectedField, obj *model.CueTrack) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
......@@ -455,7 +408,7 @@ func (ec *executionContext) _PlayListItem_file(ctx context.Context, field graphq
}
}()
fc := &graphql.FieldContext{
Object: "PlayListItem",
Object: "CueTrack",
Field: field,
Args: nil,
IsMethod: false,
......@@ -481,7 +434,7 @@ func (ec *executionContext) _PlayListItem_file(ctx context.Context, field graphq
return ec.marshalNString2string(ctx, field.Selections, res)
}
func (ec *executionContext) _PlayListItem_start(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
func (ec *executionContext) _PlayListItem_id(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
......@@ -498,7 +451,7 @@ func (ec *executionContext) _PlayListItem_start(ctx context.Context, field graph
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Start, nil
return obj.Id, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -510,12 +463,12 @@ func (ec *executionContext) _PlayListItem_start(ctx context.Context, field graph
}
return graphql.Null
}
res := resTmp.(int64)
res := resTmp.(int)
fc.Result = res
return ec.marshalNInt642int64(ctx, field.Selections, res)
return ec.marshalNInt2int(ctx, field.Selections, res)
}
func (ec *executionContext) _PlayListItem_stop(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
func (ec *executionContext) _PlayListItem_track(ctx context.Context, field graphql.CollectedField, obj *model.PlayListItem) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
......@@ -526,13 +479,13 @@ func (ec *executionContext) _PlayListItem_stop(ctx context.Context, field graphq
Object: "PlayListItem",
Field: field,
Args: nil,
IsMethod: false,
IsMethod: true,
}
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Stop, nil
return ec.resolvers.PlayListItem().Track(rctx, obj)
})
if err != nil {
ec.Error(ctx, err)
......@@ -544,9 +497,9 @@ func (ec *executionContext) _PlayListItem_stop(ctx context.Context, field graphq
}
return graphql.Null
}
res := resTmp.(int64)
res := resTmp.(*model.CueTrack)
fc.Result = res
return ec.marshalNInt642int64(ctx, field.Selections, res)
return ec.marshalNCueTrack2ᚖgoᚗtouhouᚗfmᚋradioᚋserverᚋplaylistᚋinternalᚋgraphqlᚋmodelᚐCueTrack(ctx, field.Selections, res)
}
func (ec *executionContext) _Query_playlistVersion(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
......@@ -1855,13 +1808,13 @@ func (ec *executionContext) __Entity(ctx context.Context, sel ast.SelectionSet,
switch obj := (obj).(type) {
case nil:
return graphql.Null
case model.PlayListItem:
return ec._PlayListItem(ctx, sel, &obj)
case *model.PlayListItem:
case model.CueTrack:
return ec._CueTrack(ctx, sel, &obj)
case *model.CueTrack:
if obj == nil {
return graphql.Null
}
return ec._PlayListItem(ctx, sel, obj)
return ec._CueTrack(ctx, sel, obj)
default:
panic(fmt.Errorf("unexpected type %T", obj))
}
......@@ -1871,35 +1824,32 @@ func (ec *executionContext) __Entity(ctx context.Context, sel ast.SelectionSet,
// region **************************** object.gotpl ****************************
var entityImplementors = []string{"Entity"}
var cueTrackImplementors = []string{"CueTrack", "_Entity"}
func (ec *executionContext) _Entity(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, entityImplementors)
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
Object: "Entity",
})
func (ec *executionContext) _CueTrack(ctx context.Context, sel ast.SelectionSet, obj *model.CueTrack) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, cueTrackImplementors)
out := graphql.NewFieldSet(fields)
var invalids uint32
for i, field := range fields {
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("Entity")
case "findPlayListItemByFileAndStartAndStop":
field := field
out.Concurrently(i, func() (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Entity_findPlayListItemByFileAndStartAndStop(ctx, field)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
})
out.Values[i] = graphql.MarshalString("CueTrack")
case "start":
out.Values[i] = ec._CueTrack_start(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "stop":
out.Values[i] = ec._CueTrack_stop(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "file":
out.Values[i] = ec._CueTrack_file(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
......@@ -1911,7 +1861,7 @@ func (ec *executionContext) _Entity(ctx context.Context, sel ast.SelectionSet) g
return out
}
var playListItemImplementors = []string{"PlayListItem", "_Entity"}
var playListItemImplementors = []string{"PlayListItem"}
func (ec *executionContext) _PlayListItem(ctx context.Context, sel ast.SelectionSet, obj *model.PlayListItem) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, playListItemImplementors)
......@@ -1925,23 +1875,22 @@ func (ec *executionContext) _PlayListItem(ctx context.Context, sel ast.Selection
case "id":
out.Values[i] = ec._PlayListItem_id(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "file":
out.Values[i] = ec._PlayListItem_file(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "start":
out.Values[i] = ec._PlayListItem_start(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "stop":
out.Values[i] = ec._PlayListItem_stop(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
atomic.AddUint32(&invalids, 1)
}
case "track":
field := field
out.Concurrently(i, func() (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._PlayListItem_track(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
})
default:
panic("unknown field " + strconv.Quote(field.Name))
}
......@@ -2323,6 +2272,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
return res
}
func (ec *executionContext) marshalNCueTrack2goᚗtouhouᚗfmᚋradioᚋserverᚋplaylistᚋinternalᚋgraphqlᚋmodelᚐCueTrack(ctx context.Context, sel ast.SelectionSet, v model.CueTrack) graphql.Marshaler {
return ec._CueTrack(ctx, sel, &v)
}
func (ec *executionContext) marshalNCueTrack2ᚖgoᚗtouhouᚗfmᚋradioᚋserverᚋplaylistᚋinternalᚋgraphqlᚋmodelᚐCueTrack(ctx context.Context, sel ast.SelectionSet, v *model.CueTrack) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
return ec._CueTrack(ctx, sel, v)
}
func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) {
res, err := graphql.UnmarshalInt(v)
return res, graphql.WrapErrorWithInputPath(ctx, err)
......@@ -2394,16 +2357,6 @@ func (ec *executionContext) marshalNPlayListItem2ᚕgoᚗtouhouᚗfmᚋradioᚋs
return ret
}
func (ec *executionContext) marshalNPlayListItem2ᚖgoᚗtouhouᚗfmᚋradioᚋserverᚋplaylistᚋinternalᚋgraphqlᚋmodelᚐPlayListItem(ctx context.Context, sel ast.SelectionSet, v *model.PlayListItem) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
return ec._PlayListItem(ctx, sel, v)
}