diff --git a/examples/apollo-tracing.graphql b/examples/apollo-tracing.graphql deleted file mode 100644 index 368ff53c17..0000000000 --- a/examples/apollo-tracing.graphql +++ /dev/null @@ -1,14 +0,0 @@ -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(url: "http://jsonplaceholder.typicode.com/posts") -} - -type Post { - id: Int! - userId: Int! - title: String! - body: String! -} diff --git a/examples/apollo-tracing.yaml b/examples/apollo-tracing.yaml new file mode 100644 index 0000000000..5b6d82d593 --- /dev/null +++ b/examples/apollo-tracing.yaml @@ -0,0 +1,14 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +telemetry: + export: + apollo: + apiKey: "1234" + graphRef: "abc@123" + +links: + - src: ./jsonplaceholder.graphql diff --git a/examples/apollo_federation_subgraph_post.graphql b/examples/apollo_federation_subgraph_post.graphql index b1e36ab105..840e97f7aa 100644 --- a/examples/apollo_federation_subgraph_post.graphql +++ b/examples/apollo_federation_subgraph_post.graphql @@ -1,7 +1,3 @@ -schema @server(port: 8001, enableFederation: true) @upstream(httpCache: 42, batch: {delay: 100}) { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") } diff --git a/examples/apollo_federation_subgraph_post.yaml b/examples/apollo_federation_subgraph_post.yaml new file mode 100644 index 0000000000..997dd6b4ac --- /dev/null +++ b/examples/apollo_federation_subgraph_post.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8001 + enableFederation: true + +upstream: + batch: + delay: 100 + httpCache: 42 + +links: + - src: ./apollo_federation_subgraph_post.graphql diff --git a/examples/apollo_federation_subgraph_user.graphql b/examples/apollo_federation_subgraph_user.graphql index 262b96684e..2e8cb17638 100644 --- a/examples/apollo_federation_subgraph_user.graphql +++ b/examples/apollo_federation_subgraph_user.graphql @@ -1,7 +1,3 @@ -schema @server(port: 8002, enableFederation: true) @upstream(httpCache: 42, batch: {delay: 100}) { - query: Query -} - type Query { user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}") } diff --git a/examples/apollo_federation_subgraph_user.yaml b/examples/apollo_federation_subgraph_user.yaml new file mode 100644 index 0000000000..868dcbd0cf --- /dev/null +++ b/examples/apollo_federation_subgraph_user.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8002 + enableFederation: true + +upstream: + batch: + delay: 100 + httpCache: 42 + +links: + - src: ./apollo_federation_subgraph_user.graphql diff --git a/examples/auth.graphql b/examples/auth.graphql index f335e85197..d2dfc8ada8 100644 --- a/examples/auth.graphql +++ b/examples/auth.graphql @@ -1,12 +1,3 @@ -schema - @server(port: 8000) - @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(url: "http://jsonplaceholder.typicode.com/posts") user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}") diff --git a/examples/auth.yaml b/examples/auth.yaml new file mode 100644 index 0000000000..ce902554c7 --- /dev/null +++ b/examples/auth.yaml @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + +upstream: + httpCache: 42 + +links: + - src: ./auth.graphql + - type: Htpasswd + id: auth-basic + src: .htpasswd + - type: Jwks + id: auth-jwt + src: .jwks diff --git a/examples/call.yaml b/examples/call.yaml new file mode 100644 index 0000000000..61f9913853 --- /dev/null +++ b/examples/call.yaml @@ -0,0 +1,4 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +links: + - src: ./call.graphql diff --git a/examples/cors.graphql b/examples/cors.graphql deleted file mode 100644 index 27a4d12674..0000000000 --- a/examples/cors.graphql +++ /dev/null @@ -1,19 +0,0 @@ -schema - @server( - port: 8000 - hostname: "0.0.0.0" - headers: {cors: {allowOrigins: ["*"], allowHeaders: ["*"], allowMethods: [POST, GET, OPTIONS]}} - ) { - query: Query -} - -type Query { - posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") -} - -type Post { - id: Int! - userId: Int! - title: String! - body: String! -} diff --git a/examples/cors.yaml b/examples/cors.yaml new file mode 100644 index 0000000000..90b644331c --- /dev/null +++ b/examples/cors.yaml @@ -0,0 +1,18 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + headers: + cors: + allowOrigins: + - "*" + allowHeaders: + - "*" + allowMethods: + - POST + - GET + - OPTIONS + +links: + - src: ./jsonplaceholder.graphql diff --git a/examples/empty-to-jsonplaceholder.graphql b/examples/empty-to-jsonplaceholder.graphql deleted file mode 100644 index 9025e80964..0000000000 --- a/examples/empty-to-jsonplaceholder.graphql +++ /dev/null @@ -1,3 +0,0 @@ -schema @server @upstream @link(type: Config, src: "jsonplaceholder.graphql") { - query: Query -} diff --git a/examples/graphql-composition.graphql b/examples/graphql-composition.graphql index b4d5e0c6d1..4643f91f21 100644 --- a/examples/graphql-composition.graphql +++ b/examples/graphql-composition.graphql @@ -1,11 +1,7 @@ # To run this example first start another tailcall server with basic example -# i.e. `tc start examples/jsonplaceholder.graphql` +# i.e. `tc start examples/jsonplaceholder.yaml` # 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(httpCache: 42, batch: {delay: 1}) { - query: Query -} - type Query { posts: [Post] @graphQL(url: "http://jsonplaceholder.typicode.com", name: "posts") } diff --git a/examples/graphql-composition.yaml b/examples/graphql-composition.yaml new file mode 100644 index 0000000000..d344c6dedd --- /dev/null +++ b/examples/graphql-composition.yaml @@ -0,0 +1,14 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8001 + queryValidation: false + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + batch: + delay: 1 + +links: + - src: ./graphql-composition.graphql diff --git a/examples/grpc-reflection.graphql b/examples/grpc-reflection.graphql deleted file mode 100644 index 841350bbe6..0000000000 --- a/examples/grpc-reflection.graphql +++ /dev/null @@ -1,42 +0,0 @@ -# for test upstream server see [repo](https://github.com/tailcallhq/tailcall/tree/main/tailcall-upstream-grpc) -schema - @server(port: 8000) - @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(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( - url: "http://localhost:50051" - method: "news.NewsService.GetMultipleNews" - body: "{{args.news}}" - batchKey: ["news", "id"] - ) -} - -type News { - id: Int - title: String - body: String - postImage: String - status: Status -} - -enum Status { - PUBLISHED - DRAFT - DELETED -} - -input NewsInput { - id: Int -} - -type NewsData { - news: [News] -} diff --git a/examples/grpc-reflection.yaml b/examples/grpc-reflection.yaml new file mode 100644 index 0000000000..0e5b35a741 --- /dev/null +++ b/examples/grpc-reflection.yaml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + +upstream: + httpCache: 42 + batch: + delay: + 10 + +links: + - src: ./grpc.graphql + - type: Grpc + # for test upstream server see [repo](https://github.com/tailcallhq/tailcall/tree/main/tailcall-upstream-grpc) + src: http://localhost:50051 + headers: + - key: authorization + value: Bearer 123 diff --git a/examples/grpc.graphql b/examples/grpc.graphql index 995cea0043..cd50e4532d 100644 --- a/examples/grpc.graphql +++ b/examples/grpc.graphql @@ -1,20 +1,12 @@ -# for test upstream server see [repo](https://github.com/tailcallhq/rust-grpc) -schema - @server(port: 8000) - @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(url: "http://localhost:50051", method: "news.NewsService.GetAllNews") newsById(news: NewsInput!): News! - @grpc(url: "http://localhost:50051", method: "news.NewsService.GetNews", body: "{{.args.news}}") + @grpc(url: "http://localhost:50051", method: "news.NewsService.GetNews", body: "{{args.news}}") newsByIdBatch(news: NewsInput!): News! @grpc( url: "http://localhost:50051" method: "news.NewsService.GetMultipleNews" - body: "{{.args.news}}" + body: "{{args.news}}" batchKey: ["news", "id"] ) } diff --git a/examples/grpc.yaml b/examples/grpc.yaml new file mode 100644 index 0000000000..a95202d120 --- /dev/null +++ b/examples/grpc.yaml @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + +upstream: + httpCache: 42 + batch: + delay: 10 + +links: + - src: ./grpc.graphql + # for test upstream server see [repo](https://github.com/tailcallhq/rust-grpc) + - type: Protobuf + id: news + src: "../tailcall-fixtures/fixtures/protobuf/news.proto" diff --git a/examples/jsonplaceholder.graphql b/examples/jsonplaceholder.graphql index 46aebf0105..380ddd4236 100644 --- a/examples/jsonplaceholder.graphql +++ b/examples/jsonplaceholder.graphql @@ -1,7 +1,3 @@ -schema @server(port: 8000) @upstream(httpCache: 42, batch: {delay: 100}) { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") users: [User] @http(url: "http://jsonplaceholder.typicode.com/users") diff --git a/examples/jsonplaceholder_batch.graphql b/examples/jsonplaceholder_batch.graphql index 1722c6d686..239dbe7e9e 100644 --- a/examples/jsonplaceholder_batch.graphql +++ b/examples/jsonplaceholder_batch.graphql @@ -1,7 +1,3 @@ -schema @server(port: 8000) @upstream(httpCache: 42, batch: {delay: 1, maxSize: 1000}) { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") } diff --git a/examples/jsonplaceholder_batch.yaml b/examples/jsonplaceholder_batch.yaml new file mode 100644 index 0000000000..1bc2f93803 --- /dev/null +++ b/examples/jsonplaceholder_batch.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + +upstream: + batch: + delay: 1 + maxSize: 1000 + httpCache: 42 + +links: + - src: ./jsonplaceholder_batch.graphql diff --git a/examples/jsonplaceholder_http_2.graphql b/examples/jsonplaceholder_http_2.graphql index 1d6d917e95..e9937d1973 100644 --- a/examples/jsonplaceholder_http_2.graphql +++ b/examples/jsonplaceholder_http_2.graphql @@ -1,11 +1,3 @@ -schema - @server(port: 3000, queryValidation: false, hostname: "0.0.0.0", version: HTTP2) - @link(type: Cert, src: "./example.crt") - @link(type: Key, src: "./example.key") - @upstream(httpCache: 42) { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") } diff --git a/examples/jsonplaceholder_http_2.yaml b/examples/jsonplaceholder_http_2.yaml new file mode 100644 index 0000000000..9cda653bc0 --- /dev/null +++ b/examples/jsonplaceholder_http_2.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 3000 + queryValidation: false + hostname: "0.0.0.0" + version: HTTP2 + +upstream: + httpCache: 42 + +links: + - src: ./jsonplaceholder_http_2.graphql + - type: Cert + src: ./example.crt + - type: Key + src: ./example.key diff --git a/examples/jsonplaceholder_script.graphql b/examples/jsonplaceholder_script.graphql index 1f9fa90553..257f7239a5 100644 --- a/examples/jsonplaceholder_script.graphql +++ b/examples/jsonplaceholder_script.graphql @@ -1,10 +1,3 @@ -schema - @server(port: 8000, hostname: "0.0.0.0") - @upstream(httpCache: 42, onRequest: "onRequest") - @link(type: Script, src: "scripts/echo.js") { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts", onResponseBody: "onResponse") user(id: Int!): User diff --git a/examples/jsonplaceholder_script.yaml b/examples/jsonplaceholder_script.yaml new file mode 100644 index 0000000000..d798145a11 --- /dev/null +++ b/examples/jsonplaceholder_script.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + +links: + - src: ./jsonplaceholder_script.graphql + - type: Script + src: scripts/echo.js diff --git a/examples/lint.sh b/examples/lint.sh index 0ff6895547..39a4bcac62 100755 --- a/examples/lint.sh +++ b/examples/lint.sh @@ -12,9 +12,11 @@ error_exit() { check_files() { local path="./examples" local depth=1 - local -a extensions=("-name" "*.json" -o "-name" "*.yml" -o "-name" "*.yaml" -o "-name" "*.graphql" -o "-name" "*.gql") - local command="./target/debug/tailcall check" - local -a ignore=("!" "-name" "grpc-reflection.graphql" "!" "-name" "generate.yml") + local -a extensions=("-name" "*.json" -o "-name" "*.yml" -o "-name" "*.yaml") + local command="cargo run -- check" + # ignore grpc-reflection because it requires a running grpc server + # ignore generate.yaml because it's used for generation and not service commands + local -a ignore=("!" "-name" "grpc-reflection.yaml" "!" "-name" "generate.yml") # Execute find command with constructed options and extensions find "$path" -maxdepth "$depth" \( "${extensions[@]}" \) "${ignore[@]}" -exec sh -c ' diff --git a/examples/rest-api.graphql b/examples/rest-api.graphql index bc9a45aedd..afec7d5aa3 100644 --- a/examples/rest-api.graphql +++ b/examples/rest-api.graphql @@ -1,10 +1,3 @@ -schema - @server(port: 8000, hostname: "0.0.0.0") - @upstream(httpCache: 42) - @link(type: Operation, src: "operations/routes.graphql") { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") users: [User] @http(url: "http://jsonplaceholder.typicode.com/users") diff --git a/examples/rest-api.yaml b/examples/rest-api.yaml new file mode 100644 index 0000000000..a333000460 --- /dev/null +++ b/examples/rest-api.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + +links: + - src: ./rest-api.graphql + - type: Operation + src: operations/routes.graphql diff --git a/examples/telemetry-otlp.yaml b/examples/telemetry-otlp.yaml new file mode 100644 index 0000000000..11e50a6c09 --- /dev/null +++ b/examples/telemetry-otlp.yaml @@ -0,0 +1,26 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + +links: + - src: ./telemetry.graphql + - type: Operation + src: operations/routes.graphql + - type: Protobuf + id: news + src: "../tailcall-fixtures/fixtures/protobuf/news.proto" + +telemetry: + export: + otlp: + url: "https://api.honeycomb.io:443" + headers: + - key: x-honeycomb-team + value: "{{.env.HONEYCOMB_API_KEY}}" + - key: x-honeycomb-dataset + value: tailcall diff --git a/examples/telemetry-prometheus.graphql b/examples/telemetry-prometheus.graphql deleted file mode 100644 index aecb4660f2..0000000000 --- a/examples/telemetry-prometheus.graphql +++ /dev/null @@ -1,28 +0,0 @@ -schema - @server(port: 8000, hostname: "0.0.0.0") - @upstream(httpCache: 42) - @telemetry(export: {prometheus: {path: "/metrics"}}) { - query: Query -} - -type Query { - posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") @cache(maxAge: 5000) - user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}") -} - -type User { - id: Int! - name: String! - username: String! - email: String! - phone: String - website: String -} - -type Post { - id: Int! - userId: Int! - title: String! - body: String! - user: User @http(url: "http://jsonplaceholder.typicode.com/users/{{.value.userId}}") -} diff --git a/examples/telemetry-prometheus.yaml b/examples/telemetry-prometheus.yaml new file mode 100644 index 0000000000..4cae6f964c --- /dev/null +++ b/examples/telemetry-prometheus.yaml @@ -0,0 +1,21 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + +links: + - src: ./telemetry.graphql + - type: Operation + src: operations/routes.graphql + - type: Protobuf + id: news + src: "../tailcall-fixtures/fixtures/protobuf/news.proto" + +telemetry: + export: + prometheus: + path: /metrics diff --git a/examples/telemetry-stdout.graphql b/examples/telemetry-stdout.graphql deleted file mode 100644 index 70eac8f7bb..0000000000 --- a/examples/telemetry-stdout.graphql +++ /dev/null @@ -1,25 +0,0 @@ -schema @server(port: 8000, hostname: "0.0.0.0") @upstream(httpCache: 42) @telemetry(export: {stdout: {pretty: true}}) { - query: Query -} - -type Query { - posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") @cache(maxAge: 5000) - user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}") -} - -type User { - id: Int! - name: String! - username: String! - email: String! - phone: String - website: String -} - -type Post { - id: Int! - userId: Int! - title: String! - body: String! - user: User @http(url: "http://jsonplaceholder.typicode.com/users/{{.value.userId}}") -} diff --git a/examples/telemetry-stdout.yaml b/examples/telemetry-stdout.yaml new file mode 100644 index 0000000000..1dcb69a922 --- /dev/null +++ b/examples/telemetry-stdout.yaml @@ -0,0 +1,21 @@ +# yaml-language-server: $schema=../generated/.tailcallrc.schema.json + +server: + port: 8000 + hostname: "0.0.0.0" + +upstream: + httpCache: 42 + +links: + - src: ./telemetry.graphql + - type: Operation + src: operations/routes.graphql + - type: Protobuf + id: news + src: "../tailcall-fixtures/fixtures/protobuf/news.proto" + +telemetry: + export: + stdout: + pretty: true diff --git a/examples/telemetry-otlp.graphql b/examples/telemetry.graphql similarity index 55% rename from examples/telemetry-otlp.graphql rename to examples/telemetry.graphql index 35001b9252..65a3bbd752 100644 --- a/examples/telemetry-otlp.graphql +++ b/examples/telemetry.graphql @@ -1,24 +1,3 @@ -schema - @server(port: 8000, hostname: "0.0.0.0") - @upstream(httpCache: 42) - @link(type: Operation, src: "operations/routes.graphql") - @link(id: "news", src: "../tailcall-fixtures/fixtures/protobuf/news.proto", type: Protobuf) - @telemetry( - export: { - otlp: { - url: "https://api.honeycomb.io:443" - # gather api key from https://ui.honeycomb.io and set it as env when running tailcall - headers: [ - {key: "x-honeycomb-team", value: "{{.env.HONEYCOMB_API_KEY}}"} - {key: "x-honeycomb-dataset", value: "tailcall"} - ] - } - } - requestHeaders: ["user-id"] - ) { - query: Query -} - type Query { posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/posts") @cache(maxAge: 3000) user(id: Int!): User @http(url: "http://jsonplaceholder.typicode.com/users/{{.args.id}}")