Skip to content

Commit

Permalink
feat(grpc): additional scalar types (#2002)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam McCullough <[email protected]>
Co-authored-by: Tushar Mathur <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Mehul Mathur <[email protected]>
Co-authored-by: Amit Singh <[email protected]>
  • Loading branch information
6 people authored Jun 7, 2024
1 parent 09809bb commit 345785d
Show file tree
Hide file tree
Showing 198 changed files with 4,941 additions and 207 deletions.
44 changes: 44 additions & 0 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,10 @@ input Schema {
Enum: [String!]
}
"""
Represents list of bytes
"""
scalar Bytes
"""
A date string, such as 2007-12-03, is compliant with the full-date format outlined in section 5.6 of the RFC 3339 (https://datatracker.ietf.org/doc/html/rfc3339) profile of the ISO 8601 standard for the representation of dates and times using the Gregorian calendar.
"""
scalar Date
Expand All @@ -806,6 +810,26 @@ Empty scalar type represents an empty value.
"""
scalar Empty
"""
Represents signed integer type 128 bit size as string
"""
scalar Int128
"""
Represents signed integer type 16bit size
"""
scalar Int16
"""
Represents signed integer type 32bit size
"""
scalar Int32
"""
Represents signed integer type 64bit size as string
"""
scalar Int64
"""
Represents signed integer type 8bit size
"""
scalar Int8
"""
The JSON scalar type represents JSON values as specified by [ECMA-404](www.ecma-international.org/publications/files/ECMA-ST/ ECMA-404.pdf).
"""
scalar JSON
Expand All @@ -814,6 +838,26 @@ A field whose value conforms to the standard E.164 format as specified in E.164
"""
scalar PhoneNumber
"""
Represents unsigned integer type 128bit size as string
"""
scalar UInt128
"""
Represents unsigned integer type 16bit size
"""
scalar UInt16
"""
Represents unsigned integer type 32bit size
"""
scalar UInt32
"""
Represents unsigned integer type 64bit size as string
"""
scalar UInt64
"""
Represents unsigned integer type 8bit size
"""
scalar UInt8
"""
A field whose value conforms to the standard URL format as specified in RFC3986 (https://www.ietf.org/rfc/rfc3986.txt), and it uses real JavaScript URL objects.
"""
scalar Url
82 changes: 76 additions & 6 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
}
}
},
"Bytes": {
"title": "Bytes",
"description": "Represents list of bytes",
"type": "string"
},
"Cache": {
"description": "The @cache operator enables caching for the query, field or type it is applied to.",
"type": "object",
Expand Down Expand Up @@ -295,40 +300,40 @@
},
"Date": {
"title": "Date",
"description": "A date string, such as 2007-12-03, is compliant with the full-date format outlined in section 5.6 of the RFC 3339 (https://datatracker.ietf.org/doc/html/rfc3339) profile of the ISO 8601 standard for the representation of dates and times using the Gregorian calendar.",
"type": "object",
"required": [
"Date"
],
"properties": {
"Date": {
"description": "A date string, such as 2007-12-03, is compliant with the full-date format outlined in section 5.6 of the RFC 3339 (https://datatracker.ietf.org/doc/html/rfc3339) profile of the ISO 8601 standard for the representation of dates and times using the Gregorian calendar.",
"type": "string"
}
}
},
"Email": {
"title": "Email",
"description": "field whose value conforms to the standard internet email address format as specified in HTML Spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address.",
"type": "object",
"required": [
"Email"
],
"properties": {
"Email": {
"description": "field whose value conforms to the standard internet email address format as specified in HTML Spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address.",
"type": "string",
"pattern": "/^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/"
}
}
},
"Empty": {
"title": "Empty",
"description": "Empty scalar type represents an empty value.",
"type": "object",
"required": [
"Empty"
],
"properties": {
"Empty": {
"description": "Empty scalar type represents an empty value.",
"type": "null"
}
}
Expand Down Expand Up @@ -752,6 +757,36 @@
"HTTP2"
]
},
"Int128": {
"title": "Int128",
"description": "Represents signed integer type 128 bit size as string",
"type": "integer",
"format": "int128"
},
"Int16": {
"title": "Int16",
"description": "Represents signed integer type 16bit size",
"type": "integer",
"format": "int16"
},
"Int32": {
"title": "Int32",
"description": "Represents signed integer type 32bit size",
"type": "integer",
"format": "int32"
},
"Int64": {
"title": "Int64",
"description": "Represents signed integer type 64bit size as string",
"type": "integer",
"format": "int64"
},
"Int8": {
"title": "Int8",
"description": "Represents signed integer type 8bit size",
"type": "integer",
"format": "int8"
},
"JS": {
"type": "object",
"required": [
Expand All @@ -765,13 +800,13 @@
},
"JSON": {
"title": "JSON",
"description": "The JSON scalar type represents JSON values as specified by [ECMA-404](www.ecma-international.org/publications/files/ECMA-ST/ ECMA-404.pdf).",
"type": "object",
"required": [
"JSON"
],
"properties": {
"JSON": {
"description": "The JSON scalar type represents JSON values as specified by [ECMA-404](www.ecma-international.org/publications/files/ECMA-ST/ ECMA-404.pdf).",
"type": "string"
}
}
Expand Down Expand Up @@ -888,13 +923,13 @@
},
"PhoneNumber": {
"title": "PhoneNumber",
"description": "A field whose value conforms to the standard E.164 format as specified in E.164 specification (https://en.wikipedia.org/wiki/E.164).",
"type": "object",
"required": [
"PhoneNumber"
],
"properties": {
"PhoneNumber": {
"description": "A field whose value conforms to the standard E.164 format as specified in E.164 specification (https://en.wikipedia.org/wiki/E.164).",
"type": "string"
}
}
Expand Down Expand Up @@ -1295,6 +1330,41 @@
}
}
},
"UInt128": {
"title": "UInt128",
"description": "Represents unsigned integer type 128bit size as string",
"type": "integer",
"format": "uint128",
"minimum": 0.0
},
"UInt16": {
"title": "UInt16",
"description": "Represents unsigned integer type 16bit size",
"type": "integer",
"format": "uint16",
"minimum": 0.0
},
"UInt32": {
"title": "UInt32",
"description": "Represents unsigned integer type 32bit size",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"UInt64": {
"title": "UInt64",
"description": "Represents unsigned integer type 64bit size as string",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"UInt8": {
"title": "UInt8",
"description": "Represents unsigned integer type 8bit size",
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
"Union": {
"type": "object",
"required": [
Expand Down Expand Up @@ -1472,13 +1542,13 @@
},
"Url": {
"title": "Url",
"description": "A field whose value conforms to the standard URL format as specified in RFC3986 (https://www.ietf.org/rfc/rfc3986.txt), and it uses real JavaScript URL objects.",
"type": "object",
"required": [
"Url"
],
"properties": {
"Url": {
"description": "A field whose value conforms to the standard URL format as specified in RFC3986 (https://www.ietf.org/rfc/rfc3986.txt), and it uses real JavaScript URL objects.",
"type": "string"
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/core/generator/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,18 @@ fn graphql_type_from_ref(name: &str) -> Result<GraphQLType<Unparsed>> {
fn convert_primitive_type(proto_ty: &str) -> String {
let binding = proto_ty.to_lowercase();
let proto_ty = binding.strip_prefix("type_").unwrap_or(proto_ty);
// use Int64Str and Uint64Str to represent 64bit integers as string by default
// it's how this values are represented in JSON by default in prost
// see tests in `protobuf::tests::scalars_proto_file`
match proto_ty {
"double" | "float" => "Float",
"int32" | "int64" | "fixed32" | "fixed64" | "uint32" | "uint64" => "Int",
"int32" | "sint32" | "fixed32" | "sfixed32" => "Int",
"int64" | "sint64" | "fixed64" | "sfixed64" => "Int64",
"uint32" => "UInt32",
"uint64" => "UInt64",
"bool" => "Boolean",
"string" | "bytes" => "String",
"string" => "String",
"bytes" => "Bytes",
x => x,
}
.to_string()
Expand Down Expand Up @@ -487,4 +494,12 @@ mod test {
insta::assert_snapshot!(config);
Ok(())
}

#[test]
fn test_scalar_types() -> Result<()> {
let set = compile_protobuf(&[protobuf::SCALARS])?;
let config = from_proto_resolved(&[set], "Query")?.to_sdl();
insta::assert_snapshot!(config);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ input google__protobuf__DurationInput @tag(id: "google.protobuf.Duration") {
to +315,576,000,000 inclusive. Note: these bounds are computed from:
60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
"""
seconds: Int
seconds: Int64
}

"""
Expand Down Expand Up @@ -174,7 +174,7 @@ input google__protobuf__TimestampInput @tag(id: "google.protobuf.Timestamp") {
1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
9999-12-31T23:59:59Z inclusive.
"""
seconds: Int
seconds: Int64
}

"""
Expand Down Expand Up @@ -325,7 +325,7 @@ type google__protobuf__Duration @tag(id: "google.protobuf.Duration") {
to +315,576,000,000 inclusive. Note: these bounds are computed from:
60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
"""
seconds: Int
seconds: Int64
}

"""
Expand Down Expand Up @@ -420,7 +420,7 @@ type google__protobuf__Timestamp @tag(id: "google.protobuf.Timestamp") {
1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
9999-12-31T23:59:59Z inclusive.
"""
seconds: Int
seconds: Int64
}

"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
source: src/core/generator/from_proto.rs
expression: config
---
schema @server @upstream {
query: Query
}

input scalars__ItemInput @tag(id: "scalars.Item") {
boolean: Boolean
bytesType: Bytes
doubleNum: Float
fixedint32: Int
fixedint64: Int64
floatNum: Float
integer32: Int
integer64: Int64
sfixedint32: Int
sfixedint64: Int64
sinteger32: Int
sinteger64: Int64
str: String
uinteger32: UInt32
uinteger64: UInt64
}

type Query {
scalars__Example__Get(item: scalars__ItemInput!): scalars__Result! @grpc(body: "{{.args.item}}", method: "scalars.Example.Get")
}

type scalars__Item @tag(id: "scalars.Item") {
boolean: Boolean
bytesType: Bytes
doubleNum: Float
fixedint32: Int
fixedint64: Int64
floatNum: Float
integer32: Int
integer64: Int64
sfixedint32: Int
sfixedint64: Int64
sinteger32: Int
sinteger64: Int64
str: String
uinteger32: UInt32
uinteger64: UInt64
}

type scalars__Result @tag(id: "scalars.Result") {
result: [scalars__Item]
}
Loading

1 comment on commit 345785d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.68ms 3.03ms 76.58ms 72.01%
Req/Sec 3.78k 192.64 4.32k 92.42%

452001 requests in 30.01s, 2.27GB read

Requests/sec: 15062.82

Transfer/sec: 77.31MB

Please sign in to comment.