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

Handle entity resolvers in the n+1 checker #2892

Open
meskill opened this issue Sep 24, 2024 · 3 comments · May be fixed by #2978
Open

Handle entity resolvers in the n+1 checker #2892

meskill opened this issue Sep 24, 2024 · 3 comments · May be fixed by #2978

Comments

@meskill
Copy link
Contributor

meskill commented Sep 24, 2024

Current implementation is checking only the fields while calculating n+1 issue. But after implementing #2639 resolvers could now be defined on types as well.

When considering entity resolver the entity resolver itself should be batched to prevent n+1 issue and that should be applied to any nested fields.

Handle resolvers on types while executing n+1 check

Example Configuration

schema
  @server(port: 8000)
  @upstream(baseURL: "http://jsonplaceholder.typicode.com", 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}}")
}

type User @http(path: "/users", query: [{key: "id", value: "{{.value.user.id}}"}], batchKey: ["id"]) {
  id: Int!
  name: String!
  username: String!
  email: String!
  phone: String
  website: String
}

type Post {
  id: Int!
  userId: Int!
  title: String!
  body: String!
  user: User @call(steps: [{query: "user", args: {id: "{{.value.userId}}"}}])
}

Actual

tailcall check -n ./config.graphql
 INFO File read: ./config.graphql ... ok
 INFO Config ./config.graphql ... ok
 INFO N + 1 detected: 1
query { posts { user } }

Expected

tailcall check -n ./config.graphql
 INFO File read: ./config.graphql ... ok
 INFO Config ./config.graphql ... ok
 INFO N + 1 detected: 2
query { posts { user } }
query { _entities { __typename: "User" } }
@tusharmath
Copy link
Contributor

/bounty 150

Copy link

algora-pbc bot commented Sep 24, 2024

💎 $150 bounty • Tailcall Inc.

Steps to solve:

  1. Start working: Comment /attempt #2892 with your implementation plan
  2. Submit work: Create a pull request including /claim #2892 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

🙏 Thank you for contributing to tailcallhq/tailcall!
🧐 Checkout our guidelines before you get started.
💵 More about our bounty program.

Attempt Started (GMT+0) Solution
🟢 @meskill #2978

Copy link

algora-pbc bot commented Oct 8, 2024

💡 @meskill submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants