tailcall icon indicating copy to clipboard operation
tailcall copied to clipboard

Feature Request: Support for Apollo Federation in Tailcall

Open amitksingh1490 opened this issue 6 months ago • 5 comments

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

  • Integration & Unit Tests are required.
  • Update the documentation on website

amitksingh1490 avatar Aug 10 '24 12:08 amitksingh1490