Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop check_identity from ExecutionSpec #1726

Closed
wants to merge 17 commits into from
Closed
1 change: 1 addition & 0 deletions src/config/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@
.chain(
type_def
.cache
.as_ref()

Check warning on line 215 in src/config/into_document.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/config/into_document.rs

Check warning on line 215 in src/config/into_document.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/config/into_document.rs
.map(|cache| pos(cache.to_directive())),
)
.chain(type_def.protected.as_ref().map(|protected| pos(protected.to_directive())))
.chain(type_def.tag.as_ref().map(|tag| pos(tag.to_directive())))
.collect::<Vec<_>>(),
kind,
Expand Down
23 changes: 19 additions & 4 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ use async_graphql::parser::types::*;
use async_graphql::{Pos, Positioned};
use async_graphql_value::{ConstValue, Name};

const NONEMPTY_DIRECTIVES: &[&str] = &["server", "upstream"];

fn print_directives(directives: &[Positioned<ConstDirective>]) -> String {
if directives.is_empty() {
return String::new();
}
directives
let mut directives = directives
.iter()
.map(|d| print_directive(&const_directive_to_sdl(&d.node)))
.filter(|v| !v.is_empty())
.collect::<Vec<String>>()
.join(" ")
+ " "
.join(" ");

if !directives.is_empty() {
directives.push(' ')
}

directives
}

fn pos<A>(a: A) -> Positioned<A> {
Expand Down Expand Up @@ -213,7 +221,14 @@ fn print_directive(directive: &DirectiveDefinition) -> String {
.join(", ");

if args.is_empty() {
format!("@{}", directive.name.node)
if NONEMPTY_DIRECTIVES
.iter()
.any(|v| directive.name.node.eq(v))
{
String::new()
} else {
format!("@{}", directive.name.node)
}
ssddOnTop marked this conversation as resolved.
Show resolved Hide resolved
} else {
format!("@{}({})", directive.name.node, args)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: src/generator/from_proto.rs
expression: result
---
schema @server @upstream {
schema {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: src/generator/from_proto.rs
expression: result
---
schema @server @upstream {
schema {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: src/generator/from_proto.rs
expression: config
---
schema @server @upstream {
schema {
query: Query
}

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
.on_thread_stop(|| {
TRACING_GUARD.take();
})
.enable_all() // need this for any http IO before 2nd runtime is created

Check warning on line 35 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L35

Added line #L35 was not covered by tests
.build()?;
rt.block_on(async { tailcall::cli::run().await })
}
Expand Down
8 changes: 4 additions & 4 deletions tests/execution/add-field-index-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ schema {
query: Query
}

type User {
name: String
type Query @addField(name: "username", path: ["users", "0", "name"]) {
users: [User] @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users")
}

type Query @addField(name: "username", path: ["users", "0", "name"]) {
users: [User] @http(path: "/users", baseURL: "http://jsonplaceholder.typicode.com")
type User {
name: String
}
```

Expand Down
6 changes: 1 addition & 5 deletions tests/execution/add-field-many-list.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
check_identity: true
---

# add-field-many-list

```graphql @server
schema @server @upstream {
schema {
query: Query
}

Expand Down
6 changes: 1 addition & 5 deletions tests/execution/add-field-many.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
check_identity: true
---

# add-field-many

```graphql @server
schema @server @upstream {
schema {
query: Query
}

Expand Down
17 changes: 7 additions & 10 deletions tests/execution/add-field-modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ schema {
query: Query
}

type User
@addField(name: "street", path: ["address", "street"])
@addField(name: "city", path: ["address", "city"])
@addField(name: "zipcode", path: ["address", "zipcode"]) {
name: String
address: Address
}

type Address {
street: String
city: String
street: String
zipcode: String
}

type Query {
user: User @http(path: "/users/1", baseURL: "http://jsonplaceholder.typicode.com")
user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
}

type User @addField(name: "street", path: ["address", "street"]) @addField(name: "city", path: ["address", "city"]) @addField(name: "zipcode", path: ["address", "zipcode"]) {
address: Address
name: String
}
```

Expand Down
16 changes: 7 additions & 9 deletions tests/execution/add-field-with-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ schema {
query: Query
}

type User {
address: Address
}

type Address {
street: String
geo: Geo
street: String
}

type Geo {
lat: String
lng: String
}

type Query
@addField(name: "lat", path: ["user", "address", "geo", "lat"])
@addField(name: "lng", path: ["user", "address", "geo", "lng"]) {
user: User @http(path: "/users/1", baseURL: "http://jsonplaceholder.typicode.com")
type Query @addField(name: "lat", path: ["user", "address", "geo", "lat"]) @addField(name: "lng", path: ["user", "address", "geo", "lng"]) {
user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
}

type User {
address: Address
}
```

Expand Down
9 changes: 5 additions & 4 deletions tests/execution/add-field-with-modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ schema {
query: Query
}

type Query @addField(name: "user1", path: ["person1", "name"]) @addField(name: "user2", path: ["person2", "name"]) {
person1: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
person2: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/2")
}

type User {
name: String
}
type Query @addField(name: "user1", path: ["person1", "name"]) @addField(name: "user2", path: ["person2", "name"]) {
person1: User @http(path: "/users/1", baseURL: "http://jsonplaceholder.typicode.com")
person2: User @http(path: "/users/2", baseURL: "http://jsonplaceholder.typicode.com")
}
```

```yml @mock
Expand Down
10 changes: 5 additions & 5 deletions tests/execution/add-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ schema {
query: Query
}

type User @addField(name: "lat", path: ["address", "geo", "lat"]) {
address: Address
}

type Address {
geo: Geo
}
Expand All @@ -18,7 +14,11 @@ type Geo {
}

type Query {
user: User @http(path: "/users/1", baseURL: "http://jsonplaceholder.typicode.com")
user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
}

type User @addField(name: "lat", path: ["address", "geo", "lat"]) {
address: Address
}
```

Expand Down
6 changes: 2 additions & 4 deletions tests/execution/apollo-tracing.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Apollo Tracing

```graphql @server
schema
@server(port: 8000, graphiql: true, hostname: "0.0.0.0")
@telemetry(export: {apollo: {apiKey: "<api_key>", graphRef: "tailcall-demo-3@current"}}) {
schema @server(graphiql: true, hostname: "0.0.0.0", port: 8000) {
query: Query
}

type Query {
hello: String! @http(path: "/", baseURL: "http://api.com")
hello: String! @http(baseURL: "http://api.com", path: "/")
}
```

Expand Down
16 changes: 8 additions & 8 deletions tests/execution/auth-basic.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Auth with BasicAuth

```graphql @server
schema @server(port: 8000, graphiql: true) @link(id: "htpasswd", type: Htpasswd, src: ".htpasswd") {
schema @server(graphiql: true, port: 8000) @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) {
query: Query
mutation: Mutation
}

type Query {
scalar: String! @expr(body: "data from public scalar")
protectedScalar: String! @protected @expr(body: "data from protected scalar")
nested: Nested! @expr(body: {name: "nested name", protected: "protected nested"})
protectedType: ProtectedType @expr(body: {name: "protected type name", nested: "protected type nested"})
}

type Mutation {
protectedType: ProtectedType @http(baseURL: "http://upstream", path: "/protected")
}
Expand All @@ -26,6 +19,13 @@ type ProtectedType @protected {
name: String!
nested: String!
}

type Query {
nested: Nested! @expr(body: {name: "nested name", protected: "protected nested"})
protectedScalar: String! @expr(body: "data from protected scalar") @protected
protectedType: ProtectedType @expr(body: {name: "protected type name", nested: "protected type nested"})
scalar: String! @expr(body: "data from public scalar")
}
```

```text @file:.htpasswd
Expand Down
16 changes: 8 additions & 8 deletions tests/execution/auth-jwt.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Auth with JWT loaded from expr

```graphql @server
schema @server(port: 8000, graphiql: true) @link(id: "jwks", type: Jwks, src: "jwks.json") {
schema @server(graphiql: true, port: 8000) @link(id: "jwks", src: "jwks.json", type: Jwks) {
query: Query
mutation: Mutation
}

type Query {
scalar: String! @expr(body: "data from public scalar")
protectedScalar: String! @protected @expr(body: "data from protected scalar")
nested: Nested! @expr(body: {name: "nested name", protected: "protected nested"})
protectedType: ProtectedType @expr(body: {name: "protected type name", nested: "protected type nested"})
}

type Mutation {
protectedType: ProtectedType @http(baseURL: "http://upstream", path: "/protected")
}
Expand All @@ -26,6 +19,13 @@ type ProtectedType @protected {
name: String!
nested: String!
}

type Query {
nested: Nested! @expr(body: {name: "nested name", protected: "protected nested"})
protectedScalar: String! @expr(body: "data from protected scalar") @protected
protectedType: ProtectedType @expr(body: {name: "protected type name", nested: "protected type nested"})
scalar: String! @expr(body: "data from public scalar")
}
```

```json @file:jwks.json
Expand Down
6 changes: 1 addition & 5 deletions tests/execution/auth.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
check_identity: true
---

# auth

```graphql @server
schema @server @upstream @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) @link(id: "jwks", src: "jwks.json", type: Jwks) {
schema @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) @link(id: "jwks", src: "jwks.json", type: Jwks) {
query: Query
}

Expand Down
15 changes: 7 additions & 8 deletions tests/execution/batching-default.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Batching default

```graphql @server
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: true, batch: {delay: 10}) {
schema @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts?id=11&id=3&foo=1")
}

type Post {
body: String
id: Int
title: String
body: String
user: User @http(batchKey: ["id"], path: "/users", query: [{key: "id", value: "{{value.userId}}"}, {key: "foo", value: "bar"}])
userId: Int!
user: User
@http(path: "/users", query: [{key: "id", value: "{{value.userId}}"}, {key: "foo", value: "bar"}], batchKey: ["id"])
}

type Query {
posts: [Post] @http(path: "/posts?id=11&id=3&foo=1")
}

type User {
Expand Down
17 changes: 7 additions & 10 deletions tests/execution/batching-group-by-default.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Batching group by default

```graphql @server
schema
@server
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: true, batch: {delay: 1, maxSize: 1000}) {
schema @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 1, headers: [], maxSize: 1000}, httpCache: true) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts?id=11&id=3&foo=1")
}

type Post {
body: String
id: Int
title: String
body: String
user: User @http(batchKey: ["id"], path: "/users", query: [{key: "id", value: "{{value.userId}}"}, {key: "foo", value: "bar"}])
userId: Int!
user: User
@http(batchKey: ["id"], path: "/users", query: [{key: "id", value: "{{value.userId}}"}, {key: "foo", value: "bar"}])
}

type Query {
posts: [Post] @http(path: "/posts?id=11&id=3&foo=1")
}

type User {
Expand Down
Loading
Loading