Skip to content

Commit

Permalink
feat: add support for url in HTTP (#3045)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
ssddOnTop and tusharmath authored Oct 22, 2024
1 parent fc08e4b commit 45230de
Show file tree
Hide file tree
Showing 601 changed files with 1,786 additions and 2,890 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ indenter = "0.3.3"
derive_more = { workspace = true }
strum = "0.26.2"
dashmap = "6.1.0"
urlencoding = "2.1.3"

[dev-dependencies]
datatest-stable = "0.2.9"
Expand Down
7 changes: 2 additions & 5 deletions examples/apollo-tracing.graphql
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
schema
@server(port: 8000, hostname: "0.0.0.0")
@upstream(baseURL: "http://jsonplaceholder.typicode.com")
@telemetry(export: {apollo: {apiKey: "1234", graphRef: "abc@123"}}) {
schema @server(port: 8000, hostname: "0.0.0.0") @telemetry(export: {apollo: {apiKey: "1234", graphRef: "abc@123"}}) {
query: Query
}

type Query @cache(maxAge: 30000) {
posts: [Post] @http(path: "/posts")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
}

type Post {
Expand Down
20 changes: 14 additions & 6 deletions examples/apollo_federation_subgraph_post.graphql
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
schema
@server(port: 8001, enableFederation: true)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
schema @server(port: 8001, enableFederation: true) @upstream(httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
}

type User @http(path: "/users", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
type User
@http(
url: "http://jsonplaceholder.typicode.com/users"
query: [{key: "id", value: "{{.value.id}}"}]
batchKey: ["id"]
) {
id: Int!
}

type Post @http(path: "/posts", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
type Post
@http(
url: "http://jsonplaceholder.typicode.com/posts"
query: [{key: "id", value: "{{.value.id}}"}]
batchKey: ["id"]
) {
id: Int!
userId: Int!
title: String!
Expand Down
13 changes: 8 additions & 5 deletions examples/apollo_federation_subgraph_user.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
schema
@server(port: 8002, enableFederation: true)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
schema @server(port: 8002, enableFederation: true) @upstream(httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
user(id: Int!): User @http(path: "/users/{{.args.id}}")
user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")
}

type User @http(path: "/users", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
type User
@http(
url: "http://jsonplaceholder.typicode.com/users"
query: [{key: "id", value: "{{.value.id}}"}]
batchKey: ["id"]
) {
id: Int!
name: String
username: String
Expand Down
10 changes: 5 additions & 5 deletions examples/auth.graphql
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42)
@upstream(httpCache: 42)
@link(id: "auth-basic", type: Htpasswd, src: ".htpasswd")
@link(id: "auth-jwt", type: Jwks, src: ".jwks") {
query: Query
mutation: Mutation
}

type Query {
posts: [Post] @http(path: "/posts")
user(id: Int!): User @http(path: "/users/{{.args.id}}")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")
}

type Mutation {
user(id: Int!): User @http(path: "/users/{{.args.id}}")
user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")
}

type User @protected {
Expand All @@ -30,5 +30,5 @@ type Post {
userId: Int!
title: String!
body: String! @protected
user: User @http(path: "/users/{{.value.userId}}")
user: User @http(url: "http://jsonplaceholder.typicode.com/users/{{.value.userId}}")
}
6 changes: 3 additions & 3 deletions examples/call.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @upstream(baseURL: "http://jsonplaceholder.typicode.com") {
schema {
query: Query
}

Expand All @@ -10,9 +10,9 @@ type Post {
}

type Query {
user(id: Int!): User @http(path: "/users/{{.args.id}}")
user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")
firstUser: User @call(steps: [{query: "user", args: {id: 1}}])
postFromUser(userId: Int!): [Post] @http(path: "/posts?userId={{.args.userId}}")
postFromUser(userId: Int!): [Post] @http(url: "http://jsonplaceholder.typicode.com/posts?userId={{.args.userId}}")
}

type User {
Expand Down
5 changes: 2 additions & 3 deletions examples/cors.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ schema
port: 8000
hostname: "0.0.0.0"
headers: {cors: {allowOrigins: ["*"], allowHeaders: ["*"], allowMethods: [POST, GET, OPTIONS]}}
)
@upstream(baseURL: "http://jsonplaceholder.typicode.com") {
) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
}

type Post {
Expand Down
9 changes: 4 additions & 5 deletions examples/graphql-composition.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
# i.e. `tc start examples/jsonplaceholder.graphql`
# and then you can run this example and test it on 8001 port

schema
@server(port: 8001, queryValidation: false, hostname: "0.0.0.0")
@upstream(baseURL: "http://localhost:8000/graphql", httpCache: 42, batch: {delay: 1}) {
schema @server(port: 8001, queryValidation: false, hostname: "0.0.0.0") @upstream(httpCache: 42, batch: {delay: 1}) {
query: Query
}

type Query {
posts: [Post] @graphQL(name: "posts")
posts: [Post] @graphQL(url: "http://jsonplaceholder.typicode.com", name: "posts")
}

type Post {
id: Int!
userId: Int!
title: String!
body: String!
user: User @graphQL(name: "user", args: [{key: "id", value: "{{.value.userId}}"}])
user: User
@graphQL(url: "http://jsonplaceholder.typicode.com", name: "user", args: [{key: "id", value: "{{.value.userId}}"}])
}

type User {
Expand Down
14 changes: 10 additions & 4 deletions examples/grpc-reflection.graphql
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# for test upstream server see [repo](https://github.com/tailcallhq/tailcall/tree/main/tailcall-upstream-grpc)
schema
@server(port: 8000)
@upstream(baseURL: "http://localhost:50051", httpCache: 42, batch: {delay: 10})
@upstream(httpCache: 42, batch: {delay: 10})
@link(src: "http://localhost:50051", type: Grpc, headers: [{key: "authorization", value: "Bearer 123"}]) {
query: Query
}

type Query {
news: NewsData! @grpc(method: "news.NewsService.GetAllNews")
newsById(news: NewsInput!): News! @grpc(method: "news.NewsService.GetNews", body: "{{args.news}}")
news: NewsData! @grpc(url: "http://localhost:50051", method: "news.NewsService.GetAllNews")
newsById(news: NewsInput!): News!
@grpc(url: "http://localhost:50051", method: "news.NewsService.GetNews", body: "{{args.news}}")
newsByIdBatch(news: NewsInput!): News!
@grpc(method: "news.NewsService.GetMultipleNews", body: "{{args.news}}", batchKey: ["news", "id"])
@grpc(
url: "http://localhost:50051"
method: "news.NewsService.GetMultipleNews"
body: "{{args.news}}"
batchKey: ["news", "id"]
)
}

type News {
Expand Down
14 changes: 10 additions & 4 deletions examples/grpc.graphql
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# for test upstream server see [repo](https://github.com/tailcallhq/rust-grpc)
schema
@server(port: 8000)
@upstream(baseURL: "http://localhost:50051", httpCache: 42, batch: {delay: 10})
@upstream(httpCache: 42, batch: {delay: 10})
@link(id: "news", src: "../tailcall-fixtures/fixtures/protobuf/news.proto", type: Protobuf) {
query: Query
}

type Query {
news: NewsData! @grpc(method: "news.NewsService.GetAllNews")
newsById(news: NewsInput!): News! @grpc(method: "news.NewsService.GetNews", body: "{{.args.news}}")
news: NewsData! @grpc(url: "http://localhost:50051", method: "news.NewsService.GetAllNews")
newsById(news: NewsInput!): News!
@grpc(url: "http://localhost:50051", method: "news.NewsService.GetNews", body: "{{.args.news}}")
newsByIdBatch(news: NewsInput!): News!
@grpc(method: "news.NewsService.GetMultipleNews", body: "{{.args.news}}", batchKey: ["news", "id"])
@grpc(
url: "http://localhost:50051"
method: "news.NewsService.GetMultipleNews"
body: "{{.args.news}}"
batchKey: ["news", "id"]
)
}

type News {
Expand Down
10 changes: 4 additions & 6 deletions examples/jsonplaceholder.graphql
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
schema @server(port: 8000) @upstream(httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
users: [User] @http(path: "/users")
user(id: Int!): User @http(path: "/users/{{.args.id}}")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
users: [User] @http(url: "http://jsonplaceholder.typicode.com/users")
user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")
greet: String @expr(body: "Hello World!")
}

Expand Down
7 changes: 3 additions & 4 deletions examples/jsonplaceholder.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"port": 8000
},
"upstream": {
"baseURL": "http://jsonplaceholder.typicode.com",
"httpCache": 42
},
"schema": {
Expand Down Expand Up @@ -37,7 +36,7 @@
"name": "User"
},
"http": {
"path": "/users/{{value.userId}}"
"url": "http://jsonplaceholder.typicode.com/users/{{value.userId}}"
}
},
"userId": {
Expand All @@ -57,7 +56,7 @@
}
},
"http": {
"path": "/posts"
"url": "http://jsonplaceholder.typicode.com/posts"
}
},
"user": {
Expand All @@ -73,7 +72,7 @@
}
},
"http": {
"path": "/users/{{args.id}}"
"url": "http://jsonplaceholder.typicode.com/users/{{args.id}}"
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions examples/jsonplaceholder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ server:
hostname: 0.0.0.0
port: 8000
upstream:
baseURL: http://jsonplaceholder.typicode.com
httpCache: 42
schema:
query: Query
Expand All @@ -25,7 +24,7 @@ types:
type:
name: User
http:
path: /users/{{value.userId}}
url: http://jsonplaceholder.typicode.com/users/{{value.userId}}
userId:
type:
name: Int
Expand All @@ -37,7 +36,7 @@ types:
list:
name: Post
http:
path: /posts
url: http://jsonplaceholder.typicode.com/posts
user:
type:
name: User
Expand All @@ -47,7 +46,7 @@ types:
name: Int
required: true
http:
path: /users/{{args.id}}
url: http://jsonplaceholder.typicode.com/users/{{args.id}}
User:
fields:
email:
Expand Down
13 changes: 8 additions & 5 deletions examples/jsonplaceholder_batch.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 1, maxSize: 1000}) {
schema @server(port: 8000) @upstream(httpCache: 42, batch: {delay: 1, maxSize: 1000}) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts")
}

type User {
Expand All @@ -22,5 +20,10 @@ type Post {
userId: Int!
title: String!
body: String!
user: User @http(path: "/users", query: [{key: "id", value: "{{.value.userId}}"}], batchKey: ["id"])
user: User
@http(
url: "http://jsonplaceholder.typicode.com/users"
query: [{key: "id", value: "{{.value.userId}}"}]
batchKey: ["id"]
)
}
5 changes: 2 additions & 3 deletions examples/jsonplaceholder_batch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"port": 8000
},
"upstream": {
"baseURL": "http://jsonplaceholder.typicode.com",
"httpCache": 42,
"batch": {
"maxSize": 1000,
Expand Down Expand Up @@ -40,7 +39,7 @@
"name": "User"
},
"http": {
"path": "/users",
"url": "http://jsonplaceholder.typicode.com/users",
"query": [
{
"key": "id",
Expand All @@ -67,7 +66,7 @@
}
},
"http": {
"path": "/posts"
"url": "http://jsonplaceholder.typicode.com/posts"
}
}
}
Expand Down
Loading

0 comments on commit 45230de

Please sign in to comment.