@graphql-hive/federation-gateway-audit
Version:
Audit tool for Apollo Federation Gateway
289 lines (273 loc) • 5.58 kB
JavaScript
import { c as createSubgraph, a as createTest, s as serve } from './testkit-BtZjdl4n.js';
import '@apollo/composition';
import 'graphql';
import 'fets';
import '@apollo/subgraph';
import 'graphql-yoga';
const products = [
{
id: "p1",
pid: "p1-pid",
categoryId: "c1"
},
{
id: "p2",
pid: "p2-pid",
categoryId: "c2"
},
{
id: "p3",
pid: "p3-pid",
categoryId: "c1"
}
];
const categories = [
{
id: "c1",
name: "c1-name",
details: {
products: products.filter((p) => p.categoryId === "c1").length
}
},
{
id: "c2",
name: "c2-name",
details: {
products: products.filter((p) => p.categoryId === "c2").length
}
}
];
var a = createSubgraph("a", {
typeDefs: (
/* GraphQL */
`
extend schema
type Query {
products: [Product!]!
}
type Product {
id: ID!
pid: ID!
category: Category
}
type Category {
id: ID!
name: String!
}
`
),
resolvers: {
Query: {
products() {
return products.map((p) => ({
id: p.id,
pid: p.pid,
categoryId: p.categoryId
}));
}
},
Product: {
__resolveReference(key) {
const product = products.find(
(p) => p.id === key.id && ("pid" in key ? p.pid === key.pid : true)
);
if (!product) {
return null;
}
return {
id: product.id,
pid: product.pid,
categoryId: product.categoryId
};
},
category(product) {
const category = categories.find((c) => c.id === product.categoryId);
if (!category) {
return null;
}
return {
id: category.id,
name: category.name
};
}
},
Category: {
__resolveReference(key) {
const category = categories.find((c) => c.id === key.id);
if (!category) {
return null;
}
return {
id: category.id,
name: category.name
};
}
}
}
});
var b = createSubgraph("b", {
typeDefs: (
/* GraphQL */
`
extend schema
type Product {
id: ID!
pid: ID!
category: Category
}
type Category {
id: ID!
name: String!
}
`
),
resolvers: {
Product: {
__resolveReference(key) {
const product = products.find(
(p) => p.id === key.id && p.pid === key.pid
);
if (!product) {
return null;
}
return {
id: product.id,
pid: product.pid,
categoryId: product.categoryId
};
},
category(product) {
const category = categories.find((c) => c.id === product.categoryId);
if (!category) {
return null;
}
return {
id: category.id,
name: category.name
};
}
},
Category: {
__resolveReference(key) {
const category = categories.find((c) => c.id === key.id);
if (!category) {
return null;
}
return {
id: category.id,
name: category.name
};
}
}
}
});
var c = createSubgraph("c", {
typeDefs: (
/* GraphQL */
`
extend schema
type Category {
details: CategoryDetails
}
type Product {
id: ID!
pid: ID!
category: Category
}
type CategoryDetails {
products: Int
}
`
),
resolvers: {
Product: {
__resolveReference(key) {
const product = products.find(
(p) => p.id === key.id && p.pid === key.pid
);
if (!product) {
return null;
}
return {
id: product.id,
pid: product.pid,
categoryId: product.categoryId
};
},
category(product) {
const category = categories.find((c) => c.id === product.categoryId);
if (!category) {
return null;
}
return {
details: category.details
};
}
}
}
});
var test = [
createTest(
/* GraphQL */
`
query {
products {
id
category {
id
details {
products
}
}
}
}
`,
{
data: {
products: [
{
id: "p1",
category: {
id: "c1",
details: {
products: 2
}
}
},
{
id: "p2",
category: {
id: "c2",
details: {
products: 1
}
}
},
{
id: "p3",
category: {
id: "c1",
details: {
products: 2
}
}
}
]
}
}
)
];
var index = serve("parent-entity-call", [a, b, c], test);
export { index as default };