tailcallhq / tailcall

High Performance GraphQL Runtime
https://tailcall.run
Apache License 2.0
1.3k stars 254 forks source link

bug: batching doesn't work graphql. #3127

Closed laststylebender14 closed 6 days ago

laststylebender14 commented 6 days ago

for following example, ideally batching should work by sending all userId's in single upstream request but it doesn't.

schema @server(port: 8001, queryValidation: false, hostname: "0.0.0.0") @upstream(httpCache: 42, batch: {delay: 10}) {
  query: Query
}

type Query {
  posts: [Post] @graphQL(url: "http://127.0.0.1:8000/graphql", name: "posts")
}

type Post {
  id: Int!
  userId: Int!
  user: User
    @graphQL(url: "http://127.0.0.1:8000/graphql", name: "user", args: [{key: "id", value: "{{.value.userId}}"}], batch: true)
}

type User {
  id: Int!
  name(id: Int): String!
}

following error is thrown on server.

on base tailcall server.

ERROR error=Deserialization Error: invalid type: unit value, expected struct Response

on upstream graphql server

INFO GET http://jsonplaceholder.typicode.com/posts HTTP/1.1
ERROR Failed to parse request: [{ "query": "query { user(id: 7) { name id } }" },{ "query": "query { user(id: 5) { name id } }" },{ "query": "query { user(id: 10) { name id } }" },{ "query": "query { user(id: 1) { name id } }" },{ "query": "query { user(id: 2) { name id } }" },{ "query": "query { user(id: 6) { name id } }" },{ "query": "query { user(id: 3) { name id } }" },{ "query": "query { user(id: 4) { name id } }" },{ "query": "query { user(id: 9) { name id } }" },{ "query": "query { user(id: 8) { name id } }" }]

query used:

# 
query {
  posts {
    id
    user {
      name
    }
  }
}
laststylebender14 commented 6 days ago

batchRequests capability was disabled on upstream, enabling it fixes the issue.