Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
re-add snapshot tests (#76)
Browse files Browse the repository at this point in the history
Accidentally dropped it when doing the repo structure cleanup in
#68.....
  • Loading branch information
dariuszkuc authored Nov 3, 2023
1 parent 3ebe215 commit aa0575a
Show file tree
Hide file tree
Showing 11 changed files with 649 additions and 0 deletions.
185 changes: 185 additions & 0 deletions tests/composition_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
mod subgraph;

#[cfg(test)]
mod tests {
use apollo_compiler::Schema;
use apollo_federation::subgraph::Subgraph;
use apollo_federation::Supergraph;

fn print_sdl(schema: &Schema) -> String {
let mut schema = schema.clone();
schema.types.sort_keys();
schema.directive_definitions.sort_keys();
schema.to_string()
}

#[test]
fn can_compose_supergraph() {
let s1 = Subgraph::parse_and_expand(
"Subgraph1",
"https://subgraph1",
r#"
type Query {
t: T
}
type T @key(fields: "k") {
k: ID
}
type S {
x: Int
}
union U = S | T
"#,
)
.unwrap();
let s2 = Subgraph::parse_and_expand(
"Subgraph2",
"https://subgraph2",
r#"
type T @key(fields: "k") {
k: ID
a: Int
b: String
}
enum E {
V1
V2
}
"#,
)
.unwrap();

let supergraph = Supergraph::compose(vec![&s1, &s2]).unwrap();
insta::assert_snapshot!(print_sdl(&supergraph.schema));
insta::assert_snapshot!(print_sdl(&supergraph.to_api_schema()));
}

#[test]
fn can_compose_with_descriptions() {
let s1 = Subgraph::parse_and_expand(
"Subgraph1",
"https://subgraph1",
r#"
"The foo directive description"
directive @foo(url: String) on FIELD
"A cool schema"
schema {
query: Query
}
"""
Available queries
Not much yet
"""
type Query {
"Returns tea"
t(
"An argument that is very important"
x: String!
): String
}
"#,
)
.unwrap();

let s2 = Subgraph::parse_and_expand(
"Subgraph2",
"https://subgraph2",
r#"
"The foo directive description"
directive @foo(url: String) on FIELD
"An enum"
enum E {
"The A value"
A
"The B value"
B
}
"#,
)
.unwrap();

let supergraph = Supergraph::compose(vec![&s1, &s2]).unwrap();
insta::assert_snapshot!(print_sdl(&supergraph.schema));
insta::assert_snapshot!(print_sdl(&supergraph.to_api_schema()));
}

#[test]
fn can_compose_types_from_different_subgraphs() {
let s1 = Subgraph::parse_and_expand(
"SubgraphA",
"https://subgraphA",
r#"
type Query {
products: [Product!]
}
type Product {
sku: String!
name: String!
}
"#,
)
.unwrap();

let s2 = Subgraph::parse_and_expand(
"SubgraphB",
"https://subgraphB",
r#"
type User {
name: String
email: String!
}
"#,
)
.unwrap();
let supergraph = Supergraph::compose(vec![&s1, &s2]).unwrap();
insta::assert_snapshot!(print_sdl(&supergraph.schema));
insta::assert_snapshot!(print_sdl(&supergraph.to_api_schema()));
}

#[test]
fn compose_removes_federation_directives() {
let s1 = Subgraph::parse_and_expand(
"SubgraphA",
"https://subgraphA",
r#"
extend schema @link(url: "https://specs.apollo.dev/federation/v2.5", import: [ "@key", "@provides", "@external" ])
type Query {
products: [Product!] @provides(fields: "name")
}
type Product @key(fields: "sku") {
sku: String!
name: String! @external
}
"#,
)
.unwrap();

let s2 = Subgraph::parse_and_expand(
"SubgraphB",
"https://subgraphB",
r#"
extend schema @link(url: "https://specs.apollo.dev/federation/v2.5", import: [ "@key", "@shareable" ])
type Product @key(fields: "sku") {
sku: String!
name: String! @shareable
}
"#,
)
.unwrap();

let supergraph = Supergraph::compose(vec![&s1, &s2]).unwrap();
insta::assert_snapshot!(print_sdl(&supergraph.schema));
insta::assert_snapshot!(print_sdl(&supergraph.to_api_schema()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: apollo-federation/tests/composition_tests.rs
expression: print_sdl(&supergraph.to_api_schema())
---
enum E {
V1
V2
}

type Query {
t: T
}

type S {
x: Int
}

type T {
k: ID
a: Int
b: String
}

union U = S | T

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
source: apollo-federation/tests/composition_tests.rs
expression: print_sdl(&supergraph.schema)
---
schema @link(url: "https://specs.apollo.dev/link/v1.0") @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) {
query: Query
}

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) 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 INTERFACE | OBJECT

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

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

enum E @join__type(graph: SUBGRAPH2) {
V1 @join__enumValue(graph: SUBGRAPH2)
V2 @join__enumValue(graph: SUBGRAPH2)
}

type Query @join__type(graph: SUBGRAPH1) @join__type(graph: SUBGRAPH2) {
t: T @join__field(graph: SUBGRAPH1)
}

type S @join__type(graph: SUBGRAPH1) {
x: Int
}

type T @join__type(graph: SUBGRAPH1, key: "k") @join__type(graph: SUBGRAPH2, key: "k") {
k: ID
a: Int @join__field(graph: SUBGRAPH2)
b: String @join__field(graph: SUBGRAPH2)
}

union U @join__type(graph: SUBGRAPH1) @join__unionMember(graph: SUBGRAPH1, member: "S") @join__unionMember(graph: SUBGRAPH1, member: "T") = S | T

scalar join__FieldSet

enum join__Graph {
SUBGRAPH1 @join__graph(name: "Subgraph1", url: "https://subgraph1")
SUBGRAPH2 @join__graph(name: "Subgraph2", url: "https://subgraph2")
}

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
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: apollo-federation/tests/composition_tests.rs
expression: print_sdl(&supergraph.to_api_schema())
---
type Product {
sku: String!
name: String!
}

type Query {
products: [Product!]
}

type User {
name: String
email: String!
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: apollo-federation/tests/composition_tests.rs
expression: print_sdl(&supergraph.schema)
---
schema @link(url: "https://specs.apollo.dev/link/v1.0") @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) {
query: Query
}

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) 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 INTERFACE | OBJECT

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

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

type Product @join__type(graph: SUBGRAPHA) {
sku: String!
name: String!
}

type Query @join__type(graph: SUBGRAPHA) @join__type(graph: SUBGRAPHB) {
products: [Product!] @join__field(graph: SUBGRAPHA)
}

type User @join__type(graph: SUBGRAPHB) {
name: String
email: String!
}

scalar join__FieldSet

enum join__Graph {
SUBGRAPHA @join__graph(name: "SubgraphA", url: "https://subgraphA")
SUBGRAPHB @join__graph(name: "SubgraphB", url: "https://subgraphB")
}

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
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: apollo-federation/tests/composition_tests.rs
expression: print_sdl(&supergraph.to_api_schema())
---
"A cool schema"
schema {
query: Query
}

"An enum"
enum E {
"The A value"
A
"The B value"
B
}

"Available queries\nNot much yet"
type Query {
"Returns tea"
t(
"An argument that is very important"
x: String!,
): String
}

Loading

0 comments on commit aa0575a

Please sign in to comment.