UNPKG

@graphql-hive/federation-gateway-audit

Version:
265 lines (247 loc) 4.36 kB
'use strict'; var testkit = require('./testkit-CAf-AsDy.cjs'); require('@apollo/composition'); require('graphql'); require('fets'); require('@apollo/subgraph'); require('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 = testkit.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 = testkit.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 = testkit.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 = [ testkit.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" } } } } ), testkit.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 = testkit.serve("shared-root", [name, price, category], test); exports.default = index;