@graphql-hive/federation-gateway-audit
Version:
Audit tool for Apollo Federation Gateway
263 lines (246 loc) • 4.34 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 product = {
id: "1",
name: {
id: "1",
brand: "Brand 1",
model: "Model 1"
},
category: {
id: "1",
name: "Category 1"
},
price: {
id: "1",
amount: 1e3,
currency: "USD"
}};
var name = createSubgraph("name", {
typeDefs: (
/* GraphQL */
`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Query {
product: Product! @shareable
products: [Product!]! @shareable
}
type Product {
id: ID! @shareable
name: Name!
}
type Name {
id: ID!
brand: String!
model: String!
}
`
),
resolvers: {
Query: {
product() {
return {
id: product.id,
name: product.name
};
},
products() {
return [
{
id: product.id,
name: product.name
}
];
}
}
}
});
var price = createSubgraph("price", {
typeDefs: (
/* GraphQL */
`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Query {
product: Product! @shareable
products: [Product!]! @shareable
}
type Product {
id: ID! @shareable
price: Price!
}
type Price {
id: ID!
amount: Int!
currency: String!
}
`
),
resolvers: {
Query: {
product() {
return {
id: product.id,
price: product.price
};
},
products() {
return [
{
id: product.id,
price: product.price
}
];
}
}
}
});
var category = createSubgraph("category", {
typeDefs: (
/* GraphQL */
`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Query {
product: Product! @shareable
products: [Product!]! @shareable
}
type Product {
id: ID! @shareable
category: Category!
}
type Category {
id: ID!
name: String!
}
`
),
resolvers: {
Query: {
product() {
return {
id: product.id,
category: product.category
};
},
products() {
return [
{
id: product.id,
category: product.category
}
];
}
}
}
});
var test = [
createTest(
/* GraphQL */
`
query {
product {
id
name {
id
brand
model
}
category {
id
name
}
price {
id
amount
currency
}
}
}
`,
{
data: {
product: {
id: "1",
name: {
id: "1",
brand: "Brand 1",
model: "Model 1"
},
price: {
id: "1",
amount: 1e3,
currency: "USD"
},
category: {
id: "1",
name: "Category 1"
}
}
}
}
),
createTest(
/* GraphQL */
`
query {
products {
id
name {
id
brand
model
}
category {
id
name
}
price {
id
amount
currency
}
}
}
`,
{
data: {
products: [
{
id: "1",
name: {
id: "1",
brand: "Brand 1",
model: "Model 1"
},
price: {
id: "1",
amount: 1e3,
currency: "USD"
},
category: {
id: "1",
name: "Category 1"
}
}
]
}
}
)
];
var index = serve("shared-root", [name, price, category], test);
export { index as default };