Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"77700b93798ce98eaf75c3b02b70198e7b730ddb",
# not a key: https://github.com/apollographql/router/pull/8326#issuecomment-3325655427
"58bca0271d5a2046dfa7705a5418781bc456c787",
# Cache keys, not secret keys
"165156910be987f1d28b0c0013fe45ce2ccd23c6"
]

paths = [
Expand Down Expand Up @@ -129,6 +131,7 @@
[ rules.allowlist ]
paths = [
'''^docs/source/routing/performance/caching/response-caching/invalidation.mdx$''',
'''^docs/source/routing/performance/caching/response-caching/customization.mdx$''',
]

[[ rules ]]
Expand Down
28 changes: 28 additions & 0 deletions apollo-federation/src/connectors/expand/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use insta::glob;
use crate::ApiSchemaOptions;
use crate::connectors::expand::ExpansionResult;
use crate::connectors::expand::expand_connectors;
use crate::schema::FederationSchema;
use crate::supergraph::extract_subgraphs_from_supergraph;

#[test]
fn it_expand_supergraph() {
Expand All @@ -29,6 +31,32 @@ fn it_expand_supergraph() {
});
}

/// @cacheTag: The expanded supergraph's @join__directive `graphs`
/// list includes all synthetic connector subgraphs, but only one owns the
/// field — `extract_subgraphs_from_supergraph` must tolerate this.
#[test]
fn cache_tag_on_connector_field_does_not_crash_extraction() {
let to_expand = read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/connectors/expand/tests/schemas/expand/cache_tag_on_connector.graphql"
))
.unwrap();

let ExpansionResult::Expanded { raw_sdl, .. } =
expand_connectors(&to_expand, &ApiSchemaOptions::default()).unwrap()
else {
panic!("expected expansion");
};

let schema = apollo_compiler::Schema::parse_and_validate(&raw_sdl, "expanded.graphql")
.expect("expanded supergraph should be valid GraphQL");
let fed_schema =
FederationSchema::new(schema.into_inner()).expect("should create FederationSchema");

extract_subgraphs_from_supergraph(&fed_schema, Some(true))
.expect("extract_subgraphs_from_supergraph should succeed");
}

#[test]
fn it_ignores_supergraph() {
insta::with_settings!({prepend_module_to_snapshot => false}, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.5", for: EXECUTION)
@link(url: "https://specs.apollo.dev/connect/v0.1", for: EXECUTION)
@link(url: "https://specs.apollo.dev/cacheTag/v0.1", for: EXECUTION)
@join__directive(graphs: [CONNECTORS], name: "link", args: {url: "https://specs.apollo.dev/connect/v0.1", import: ["@connect", "@source"]})
@join__directive(graphs: [CONNECTORS], name: "source", args: {name: "example", http: {baseURL: "http://example"}})
{
query: Query
}

directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION

directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean, overrideLabel: String, contextArguments: [join__ContextArgument!]) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE

directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION

directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA

input join__ContextArgument {
name: String!
type: String!
context: String!
selection: join__FieldValue!
}

scalar join__DirectiveArguments

scalar join__FieldSet

scalar join__FieldValue

enum join__Graph {
CONNECTORS @join__graph(name: "connectors", url: "none")
}

scalar link__Import

enum link__Purpose {
"""
`SECURITY` features provide metadata necessary to securely resolve fields.
"""
SECURITY

"""
`EXECUTION` features provide metadata necessary for operation execution.
"""
EXECUTION
}

type Product
@join__type(graph: CONNECTORS, key: "id")
{
id: ID!
title: String @join__field(graph: CONNECTORS)
}

type Query
@join__type(graph: CONNECTORS)
{
users: [User] @join__field(graph: CONNECTORS) @join__directive(graphs: [CONNECTORS], name: "federation__cacheTag", args: {format: "users"}) @join__directive(graphs: [CONNECTORS], name: "connect", args: {source: "example", http: {GET: "/users"}, selection: "id name"})
products: [Product] @join__field(graph: CONNECTORS) @join__directive(graphs: [CONNECTORS], name: "connect", args: {source: "example", http: {GET: "/products"}, selection: "id title"})
}

type User
@join__type(graph: CONNECTORS, key: "id")
{
id: ID!
name: String @join__field(graph: CONNECTORS)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
subgraphs:
connectors:
routing_url: none
schema:
sdl: |
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.12"
import: ["@key", "@cacheTag"]
)
@link(url: "https://specs.apollo.dev/connect/v0.1", import: ["@connect", "@source"])
@source(name: "example", http: { baseURL: "http://example" })

type Query {
users: [User] @cacheTag(format: "users") @connect(source: "example", http: { GET: "/users" }, selection: "id name")
products: [Product] @connect(source: "example", http: { GET: "/products" }, selection: "id title")
}

type User @key(fields: "id") {
id: ID!
name: String
}

type Product @key(fields: "id") {
id: ID!
title: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: apollo-federation/src/connectors/expand/tests/mod.rs
expression: api_schema
input_file: apollo-federation/src/connectors/expand/tests/schemas/expand/cache_tag_on_connector.graphql
---
directive @defer(label: String, if: Boolean! = true) on FRAGMENT_SPREAD | INLINE_FRAGMENT

type Product {
id: ID!
title: String
}

type Query {
users: [User]
products: [Product]
}

type User {
id: ID!
name: String
}
Loading
Loading