Skip to content

Commit

Permalink
chore(2818): variance based merging of types (#2927)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
meskill and tusharmath authored Oct 2, 2024
1 parent e10eab5 commit d52dcdf
Show file tree
Hide file tree
Showing 25 changed files with 1,069 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/core/blueprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod telemetry;
mod timeout;
mod union_resolver;
mod upstream;
mod wrapping_type;

pub use auth::*;
pub use blueprint::*;
Expand All @@ -31,7 +30,6 @@ pub use schema::*;
pub use server::*;
pub use timeout::GlobalTimeout;
pub use upstream::*;
pub use wrapping_type::Type;

use crate::core::config::ConfigModule;
use crate::core::try_fold::TryFold;
Expand Down
13 changes: 12 additions & 1 deletion src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,15 @@ pub struct RootSchema {
}

#[derive(
Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, DirectiveDefinition,
Serialize,
Deserialize,
Clone,
Debug,
PartialEq,
Eq,
schemars::JsonSchema,
DirectiveDefinition,
MergeRight,
)]
#[directive_definition(locations = "FieldDefinition")]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -332,6 +340,7 @@ impl Field {
schemars::JsonSchema,
DirectiveDefinition,
InputDefinition,
MergeRight,
)]
#[directive_definition(locations = "FieldDefinition")]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -554,6 +563,8 @@ impl Config {
types = self.find_connections(field.type_of.name(), types);
}
}
} else if self.find_enum(type_of).is_some() {
types.insert(type_of.into());
}
types
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/config/config_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::core::rest::{EndpointSet, Unchecked};
use crate::core::valid::{Valid, Validator};
use crate::core::Transform;

mod merge;

/// A wrapper on top of Config that contains all the resolved extensions and
/// computed values.
#[derive(Clone, Debug, Default, MergeRight)]
Expand Down
21 changes: 21 additions & 0 deletions src/core/config/config_module/fixtures/enums-1.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema {
query: Query
}

type Query {
a: A
}

enum enumInput {
A
B
}

enum enumOutput {
A
B
}

type A {
a(x: enumInput): enumOutput
}
9 changes: 9 additions & 0 deletions src/core/config/config_module/fixtures/enums-2.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum enumInput {
B
C
}

enum enumOutput {
B
C
}
13 changes: 13 additions & 0 deletions src/core/config/config_module/fixtures/enums-3.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum enumInput {
B
C
}

enum enumOutput {
B
C
}

type A {
b(x: enumOutput): enumInput
}
9 changes: 9 additions & 0 deletions src/core/config/config_module/fixtures/router.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
schema {
# @link(src: "http://localhost:4000", type: SubGraph, meta: {name: "Users"})
# @link(src: "http://localhost:5000", type: SubGraph, meta: {name: "Posts"})
query: Query
}

type Query {
version: String @expr(body: "test")
}
43 changes: 43 additions & 0 deletions src/core/config/config_module/fixtures/subgraph-posts.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
posts: [UserPost] @http(path: "/posts")
addComment(postId: Int!, comment: CommentInput!, premium: Boolean): Boolean @http(path: "/add-comment", method: POST)
searchComments(type: CommentSearch): [Comment] @http(path: "/comment")
}

interface Post {
id: Int!
body: String
}

enum Role {
ADMIN
EMPLOYEE
}

type UserPost implements Post {
id: Int!
userId: Int!
title: String!
body: String
}

input CommentInput {
userId: Int!
body: String!
}

type Comment {
body: String
}

enum CommentSearch {
TODAY
WEEK
MONTH
}
52 changes: 52 additions & 0 deletions src/core/config/config_module/fixtures/subgraph-users.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
users: [User] @http(path: "/users")
user(id: Int!): User @http(path: "/users/{{.args.id}}")
addComment(postId: Int!, comment: CommentInput!): Boolean @http(path: "/add-comment")
}

enum Role {
USER
}

type User {
id: Int!
name: String!
username: String!
email: String!
phone: String
website: String
role: Role
}

interface Post {
userId: Int!
user: User @http(path: "/users/{{.value.userId}}")
}

type UserPost implements Post {
userId: Int!
title: String
user: User @http(path: "/users/{{.value.userId}}")
}

input CommentInput {
userId: Int!
title: String
body: String!
}

type Comment {
body: String
}

enum CommentSearch {
WEEK
MONTH
YEAR
}
13 changes: 13 additions & 0 deletions src/core/config/config_module/fixtures/types-1.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schema {
query: Query
}

type Query {
a: A
}

type A {
a: String
b: Int
c: Boolean
}
5 changes: 5 additions & 0 deletions src/core/config/config_module/fixtures/types-2.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type A {
b: Int!
d: Float!
e: String
}
6 changes: 6 additions & 0 deletions src/core/config/config_module/fixtures/types-3.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type A {
a: Int
b: [Int]
c: Boolean
d: Float
}
17 changes: 17 additions & 0 deletions src/core/config/config_module/fixtures/unions-1.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
schema {
query: Query
}

type Query {
b: B
}

type A {
a: String
}

type B {
b: String
}

union Union = A | B
9 changes: 9 additions & 0 deletions src/core/config/config_module/fixtures/unions-2.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type B {
b: String
}

type C {
c: Int
}

union Union = B | C
Loading

1 comment on commit d52dcdf

@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 7.11ms 3.25ms 53.52ms 75.11%
Req/Sec 3.58k 402.53 4.29k 94.17%

427634 requests in 30.03s, 800.92MB read

Requests/sec: 14240.95

Transfer/sec: 26.67MB

Please sign in to comment.