Initial Commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { createGraphqlRegistry, GraphqlError } from "@suaveplan/api-graphql";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { federatePlugins } from "./federation.js";
|
||||
|
||||
describe("federatePlugins", () => {
|
||||
it("two plugins each extending Query both expose their fields", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const billing = createGraphqlRegistry();
|
||||
billing.addTypes(
|
||||
"type Query { _root: String } extend type Query { invoices: [String!]! }"
|
||||
);
|
||||
billing.addResolvers({ Query: { invoices: () => ["i_1"] } });
|
||||
|
||||
const crm = createGraphqlRegistry();
|
||||
crm.addTypes("extend type Query { customers: [String!]! }");
|
||||
crm.addResolvers({ Query: { customers: () => ["c_1"] } });
|
||||
|
||||
const result = federatePlugins([
|
||||
{
|
||||
plugin: "billing",
|
||||
registry: billing as never,
|
||||
},
|
||||
{ plugin: "crm", registry: crm as never },
|
||||
]);
|
||||
expect(result.merged.sdl).toContain("invoices");
|
||||
expect(result.merged.sdl).toContain("customers");
|
||||
expect(result.resolvers.Query?.invoices).toBeDefined();
|
||||
expect(result.resolvers.Query?.customers).toBeDefined();
|
||||
});
|
||||
|
||||
it("same-field collision fails with GRAPHQL.SCHEMA_COLLISION", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const a = createGraphqlRegistry();
|
||||
a.addTypes("type Query { invoices: [String!]! }");
|
||||
const b = createGraphqlRegistry();
|
||||
b.addTypes("type Query { invoices: [String!]! }");
|
||||
expect(() =>
|
||||
federatePlugins([
|
||||
{ plugin: "a", registry: a as never },
|
||||
{ plugin: "b", registry: b as never },
|
||||
])
|
||||
).toThrow(GraphqlError);
|
||||
});
|
||||
|
||||
it("supports namespace wrapping", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const billing = createGraphqlRegistry();
|
||||
billing.addTypes("extend type Query { invoices: [String!]! }");
|
||||
const result = federatePlugins([
|
||||
{
|
||||
plugin: "billing",
|
||||
registry: billing as never,
|
||||
namespace: "Billing",
|
||||
},
|
||||
]);
|
||||
expect(result.merged.sdl).toContain("Billing");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user