API: Handle null filenames properly

In the future we might want to normalize the database on empty strings
instead of null to represent this case.
This commit is contained in:
Drew DeVault 2021-09-22 09:12:25 +02:00
parent 0838d1e3ff
commit de46f494b0
4 changed files with 5 additions and 13 deletions

View File

@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.sr.ht/~sircmpwn/core-go v0.0.0-20210909084213-468752564125 h1:UbY+U6d65kx09HhIDkakHd55uGb9SSVta76uyHjqKW8=
git.sr.ht/~sircmpwn/core-go v0.0.0-20210909084213-468752564125/go.mod h1:dOzMmMQFPH0ztBhLFNo/hFLHqck1tbhgL3aNi1XnOsI=
git.sr.ht/~sircmpwn/core-go v0.0.0-20210922070418-9f634ce015a9 h1:IiDQ99t+IUhRIZ4vZtD0KPAUSGlsVEGmdw+KL3C/myE=
git.sr.ht/~sircmpwn/core-go v0.0.0-20210922070418-9f634ce015a9/go.mod h1:dOzMmMQFPH0ztBhLFNo/hFLHqck1tbhgL3aNi1XnOsI=
git.sr.ht/~sircmpwn/dowork v0.0.0-20210820133136-d3970e97def3 h1:9WCv5cK67s2SiY/R4DWT/OchEsFnfYDz3lbevKxZ4QI=

View File

@ -518,7 +518,7 @@ type Paste {
}
type File {
filename: String!
filename: String
hash: String!
contents: URL!
}
@ -815,14 +815,11 @@ func (ec *executionContext) _File_filename(ctx context.Context, field graphql.Co
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
res := resTmp.(*string)
fc.Result = res
return ec.marshalNString2string(ctx, field.Selections, res)
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
}
func (ec *executionContext) _File_hash(ctx context.Context, field graphql.CollectedField, obj *model.File) (ret graphql.Marshaler) {
@ -3245,9 +3242,6 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj
out.Values[i] = graphql.MarshalString("File")
case "filename":
out.Values[i] = ec._File_filename(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
case "hash":
field := field
out.Concurrently(i, func() (res graphql.Marshaler) {

View File

@ -5,7 +5,7 @@ import (
)
type File struct {
Filename string `json:"filename"`
Filename *string `json:"filename"`
PasteID int
BlobID int

View File

@ -87,7 +87,7 @@ type Paste {
}
type File {
filename: String!
filename: String
hash: String!
contents: URL!
}