tailcallhq / tailcall

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

Feature Request: Support for Apollo Federation in Tailcall #2639

Open amitksingh1490 opened 1 month ago

amitksingh1490 commented 1 month ago

Summary

Enable Tailcall to support Apollo Federation by adding a flag in the @server directive. When enabled, this flag will support the _entities query, allowing Tailcall to function as a subgraph in a federated architecture.

Detailed Description

To integrate Apollo Federation with Tailcall, we propose the following enhancements:

  1. Flag Addition in @server:

    • Introduce a new flag within the @server directive to enable federation support.
    • When this flag is activated, Tailcall will automatically handle the _entities query, essential for Apollo Federation's distributed schema architecture.
  2. Support for Resolver Directives on Types:

    • Enable resolver directives like @http, @grpc, @const, and others to be applied directly on Types.
    • This will allow Tailcall to infer the key fields required for federation based on the resolver configuration.
  3. Key Inference:

    • Analyze the resolvers attached to Types and automatically infer the appropriate @key directive.
    • Example:
      • For @http(path: "/users/{{.value.id}}"), the inferred key would be @key(fields: "id").
      • For the query:
        @http(path: "/users/", query: [
        {key: "id", value: "{{.value.id}}"},
        {key: "name", value: "{{.value.name}}"},
        {key: "org_id", value: "{{.value.organisation.id}}"},
        {key: "org_name", value: "{{.value.organisation.name}}"}
        ])

        The inferred key would be @key(fields: "id name organisation {id, name}").

    • If multiple resolvers are attached to the same type, multiple keys will be inferred and handled accordingly.
  4. Support for _entities Query:

    • Implement the _entities query required by Apollo Federation.
    • Example of how the query to the subgraph would look:
      type Query {
      _entities(representations: [_Any!]!): [_Entity]!
      }
      • Example query:
        query ($representations: [_Any!]!) {
        _entities(representations: $representations) {
        ... on User {
         id
         username
        }
        }
        }
      • Corresponding variable:
        {
        "representations": [
         {
           "__typename": "User",
           "id": "5"
         }
        ]
        }

References

Technical Requirements

amitksingh1490 commented 1 month ago

/bounty 380$

algora-pbc[bot] commented 1 month ago

💎 $380 bounty • Tailcall Inc.

Steps to solve:

  1. Start working: Comment /attempt #2639 with your implementation plan
  2. Submit work: Create a pull request including /claim #2639 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
🔴 @onyedikachi-david Aug 10, 2024, 7:00:15 PM WIP
🟢 @meskill #2693
onyedikachi-david commented 1 month ago

/attempt #2639

Algora profile Completed bounties Tech Active attempts Options
@onyedikachi-david    3 tailcallhq bounties
+ 2 bounties from 1 project
JavaScript, Shell
Cancel attempt
ssddOnTop commented 1 month ago

please provide some working config

algora-pbc[bot] commented 1 month ago

@onyedikachi-david: Reminder that in 1 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] commented 1 month ago

The bounty is up for grabs! Everyone is welcome to /attempt #2639 🙌

algora-pbc[bot] commented 4 weeks ago

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