diff --git a/internal/request/graphql/schema/descriptions.go b/internal/request/graphql/schema/descriptions.go index 8fccff2fb0..526e41470e 100644 --- a/internal/request/graphql/schema/descriptions.go +++ b/internal/request/graphql/schema/descriptions.go @@ -33,8 +33,8 @@ var ( client.FieldKind_NILLABLE_STRING: gql.String, client.FieldKind_STRING_ARRAY: gql.NewList(gql.NewNonNull(gql.String)), client.FieldKind_NILLABLE_STRING_ARRAY: gql.NewList(gql.String), - client.FieldKind_NILLABLE_BLOB: schemaTypes.BlobScalarType, - client.FieldKind_NILLABLE_JSON: schemaTypes.JSONScalarType, + client.FieldKind_NILLABLE_BLOB: schemaTypes.BlobScalarType(), + client.FieldKind_NILLABLE_JSON: schemaTypes.JSONScalarType(), } defaultCRDTForFieldKind = map[client.FieldKind]client.CType{ diff --git a/internal/request/graphql/schema/manager.go b/internal/request/graphql/schema/manager.go index 7009ee2e3f..d409fe96b5 100644 --- a/internal/request/graphql/schema/manager.go +++ b/internal/request/graphql/schema/manager.go @@ -166,6 +166,9 @@ func defaultTypes( crdtEnum *gql.Enum, explainEnum *gql.Enum, ) []gql.Type { + blobScalarType := schemaTypes.BlobScalarType() + jsonScalarType := schemaTypes.JSONScalarType() + return []gql.Type{ // Base Scalar types gql.Boolean, @@ -176,8 +179,8 @@ func defaultTypes( gql.String, // Custom Scalar types - schemaTypes.BlobScalarType, - schemaTypes.JSONScalarType, + blobScalarType, + jsonScalarType, // Base Query types @@ -195,10 +198,10 @@ func defaultTypes( schemaTypes.NotNullIntOperatorBlock(), schemaTypes.StringOperatorBlock(), schemaTypes.NotNullstringOperatorBlock(), - schemaTypes.JSONOperatorBlock(), - schemaTypes.NotNullJSONOperatorBlock(), - schemaTypes.BlobOperatorBlock(), - schemaTypes.NotNullBlobOperatorBlock(), + schemaTypes.JSONOperatorBlock(jsonScalarType), + schemaTypes.NotNullJSONOperatorBlock(jsonScalarType), + schemaTypes.BlobOperatorBlock(blobScalarType), + schemaTypes.NotNullBlobOperatorBlock(blobScalarType), commitsOrderArg, commitLinkObject, diff --git a/internal/request/graphql/schema/types/base.go b/internal/request/graphql/schema/types/base.go index bcfa00e477..fd49fbb45a 100644 --- a/internal/request/graphql/schema/types/base.go +++ b/internal/request/graphql/schema/types/base.go @@ -361,26 +361,26 @@ func NotNullstringOperatorBlock() *gql.InputObject { } // JSONOperatorBlock filter block for string types. -func JSONOperatorBlock() *gql.InputObject { +func JSONOperatorBlock(jsonScalarType *gql.Scalar) *gql.InputObject { return gql.NewInputObject(gql.InputObjectConfig{ Name: "JSONOperatorBlock", Description: stringOperatorBlockDescription, Fields: gql.InputObjectConfigFieldMap{ "_eq": &gql.InputObjectFieldConfig{ Description: eqOperatorDescription, - Type: JSONScalarType, + Type: jsonScalarType, }, "_ne": &gql.InputObjectFieldConfig{ Description: neOperatorDescription, - Type: JSONScalarType, + Type: jsonScalarType, }, "_in": &gql.InputObjectFieldConfig{ Description: inOperatorDescription, - Type: gql.NewList(JSONScalarType), + Type: gql.NewList(jsonScalarType), }, "_nin": &gql.InputObjectFieldConfig{ Description: ninOperatorDescription, - Type: gql.NewList(JSONScalarType), + Type: gql.NewList(jsonScalarType), }, "_like": &gql.InputObjectFieldConfig{ Description: likeStringOperatorDescription, @@ -403,26 +403,26 @@ func JSONOperatorBlock() *gql.InputObject { } // NotNullJSONOperatorBlock filter block for string! types. -func NotNullJSONOperatorBlock() *gql.InputObject { +func NotNullJSONOperatorBlock(jsonScalarType *gql.Scalar) *gql.InputObject { return gql.NewInputObject(gql.InputObjectConfig{ Name: "NotNullJSONOperatorBlock", Description: notNullStringOperatorBlockDescription, Fields: gql.InputObjectConfigFieldMap{ "_eq": &gql.InputObjectFieldConfig{ Description: eqOperatorDescription, - Type: JSONScalarType, + Type: jsonScalarType, }, "_ne": &gql.InputObjectFieldConfig{ Description: neOperatorDescription, - Type: JSONScalarType, + Type: jsonScalarType, }, "_in": &gql.InputObjectFieldConfig{ Description: inOperatorDescription, - Type: gql.NewList(gql.NewNonNull(JSONScalarType)), + Type: gql.NewList(gql.NewNonNull(jsonScalarType)), }, "_nin": &gql.InputObjectFieldConfig{ Description: ninOperatorDescription, - Type: gql.NewList(gql.NewNonNull(JSONScalarType)), + Type: gql.NewList(gql.NewNonNull(jsonScalarType)), }, "_like": &gql.InputObjectFieldConfig{ Description: likeStringOperatorDescription, @@ -444,26 +444,26 @@ func NotNullJSONOperatorBlock() *gql.InputObject { }) } -func BlobOperatorBlock() *gql.InputObject { +func BlobOperatorBlock(blobScalarType *gql.Scalar) *gql.InputObject { return gql.NewInputObject(gql.InputObjectConfig{ Name: "BlobOperatorBlock", Description: stringOperatorBlockDescription, Fields: gql.InputObjectConfigFieldMap{ "_eq": &gql.InputObjectFieldConfig{ Description: eqOperatorDescription, - Type: BlobScalarType, + Type: blobScalarType, }, "_ne": &gql.InputObjectFieldConfig{ Description: neOperatorDescription, - Type: BlobScalarType, + Type: blobScalarType, }, "_in": &gql.InputObjectFieldConfig{ Description: inOperatorDescription, - Type: gql.NewList(BlobScalarType), + Type: gql.NewList(blobScalarType), }, "_nin": &gql.InputObjectFieldConfig{ Description: ninOperatorDescription, - Type: gql.NewList(BlobScalarType), + Type: gql.NewList(blobScalarType), }, "_like": &gql.InputObjectFieldConfig{ Description: likeStringOperatorDescription, @@ -486,26 +486,26 @@ func BlobOperatorBlock() *gql.InputObject { } // NotNullJSONOperatorBlock filter block for string! types. -func NotNullBlobOperatorBlock() *gql.InputObject { +func NotNullBlobOperatorBlock(blobScalarType *gql.Scalar) *gql.InputObject { return gql.NewInputObject(gql.InputObjectConfig{ Name: "NotNullBlobOperatorBlock", Description: notNullStringOperatorBlockDescription, Fields: gql.InputObjectConfigFieldMap{ "_eq": &gql.InputObjectFieldConfig{ Description: eqOperatorDescription, - Type: BlobScalarType, + Type: blobScalarType, }, "_ne": &gql.InputObjectFieldConfig{ Description: neOperatorDescription, - Type: BlobScalarType, + Type: blobScalarType, }, "_in": &gql.InputObjectFieldConfig{ Description: inOperatorDescription, - Type: gql.NewList(gql.NewNonNull(BlobScalarType)), + Type: gql.NewList(gql.NewNonNull(blobScalarType)), }, "_nin": &gql.InputObjectFieldConfig{ Description: ninOperatorDescription, - Type: gql.NewList(gql.NewNonNull(BlobScalarType)), + Type: gql.NewList(gql.NewNonNull(blobScalarType)), }, "_like": &gql.InputObjectFieldConfig{ Description: likeStringOperatorDescription, diff --git a/internal/request/graphql/schema/types/scalars.go b/internal/request/graphql/schema/types/scalars.go index a57fe5ae67..b86c744607 100644 --- a/internal/request/graphql/schema/types/scalars.go +++ b/internal/request/graphql/schema/types/scalars.go @@ -46,7 +46,7 @@ func coerceBlob(value any) any { } } -func NewBlobScalarType() *graphql.Scalar { +func BlobScalarType() *graphql.Scalar { return graphql.NewScalar(graphql.ScalarConfig{ Name: "Blob", Description: "The `Blob` scalar type represents a binary large object.", @@ -67,8 +67,6 @@ func NewBlobScalarType() *graphql.Scalar { }) } -var BlobScalarType = NewBlobScalarType() - // coerceJSON converts the given value into a valid json string. // If the value cannot be converted nil is returned. func coerceJSON(value any) any { @@ -102,7 +100,7 @@ func coerceJSON(value any) any { } } -func NewJSONScalarType() *graphql.Scalar { +func JSONScalarType() *graphql.Scalar { return graphql.NewScalar(graphql.ScalarConfig{ Name: "JSON", Description: "The `JSON` scalar type represents a JSON string.", @@ -122,5 +120,3 @@ func NewJSONScalarType() *graphql.Scalar { }, }) } - -var JSONScalarType = NewJSONScalarType() diff --git a/internal/request/graphql/schema/types/scalars_test.go b/internal/request/graphql/schema/types/scalars_test.go index f7fe5ed4ec..fba94ce67b 100644 --- a/internal/request/graphql/schema/types/scalars_test.go +++ b/internal/request/graphql/schema/types/scalars_test.go @@ -34,7 +34,7 @@ func TestBlobScalarTypeSerialize(t *testing.T) { {false, nil}, } for _, c := range cases { - result := NewBlobScalarType().Serialize(c.input) + result := BlobScalarType().Serialize(c.input) assert.Equal(t, c.expect, result) } } @@ -60,7 +60,7 @@ func TestBlobScalarTypeParseValue(t *testing.T) { {false, nil}, } for _, c := range cases { - result := NewBlobScalarType().ParseValue(c.input) + result := BlobScalarType().ParseValue(c.input) assert.Equal(t, c.expect, result) } } @@ -82,7 +82,7 @@ func TestBlobScalarTypeParseLiteral(t *testing.T) { {&ast.ObjectValue{}, nil}, } for _, c := range cases { - result := NewBlobScalarType().ParseLiteral(c.input) + result := BlobScalarType().ParseLiteral(c.input) assert.Equal(t, c.expect, result) } } @@ -141,10 +141,10 @@ func TestJSONScalarTypeParseAndSerialize(t *testing.T) { {false, nil}, } for _, c := range cases { - parsed := JSONScalarType.ParseValue(c.input) + parsed := JSONScalarType().ParseValue(c.input) assert.Equal(t, c.expect, parsed) - serialized := JSONScalarType.Serialize(c.input) + serialized := JSONScalarType().Serialize(c.input) assert.Equal(t, c.expect, serialized) } } @@ -165,7 +165,7 @@ func TestJSONScalarTypeParseLiteral(t *testing.T) { {&ast.ObjectValue{}, nil}, } for _, c := range cases { - result := JSONScalarType.ParseLiteral(c.input) + result := JSONScalarType().ParseLiteral(c.input) assert.Equal(t, c.expect, result) } }