@graphql-hive/federation-gateway-audit
Version:
Audit tool for Apollo Federation Gateway
96 lines (80 loc) • 2.13 kB
text/typescript
import { createSubgraph } from "../../subgraph.js";
import { animals, medias, pubishPoorPlans } from "./data.js";
export default createSubgraph("a", {
typeDefs: /* GraphQL */ `
extend schema
type Query {
media: Media
book: Book
}
interface Media {
id: ID!
}
interface Animal {
id: ID!
}
type Book implements Media {
id: ID!
animals: [Animal]
}
type Dog implements Animal {
id: ID!
name: String
}
type Cat implements Animal {
id: ID!
}
`,
resolvers: {
Query: {
media() {
if (pubishPoorPlans) {
throw new Error("You should be using the 'a' subgraph!");
}
const media = medias[0];
return {
__typename: media.__typename,
id: media.id,
animals: media.animals.map((animalId) => {
const animal = animals.find((a) => a.id === animalId);
if (!animal) {
return null;
}
return {
__typename: animal.__typename,
id: animal.id,
};
}),
};
},
book() {
const book = medias[0];
return {
__typename: "Book",
id: book.id,
animals: book.animals.map((animalId) => {
const animal = animals.find((a) => a.id === animalId);
if (!animal) {
return null;
}
if (animal.__typename === "Dog") {
return {
__typename: "Dog",
id: animal.id,
name: animal.name,
};
}
return {
__typename: animal.__typename,
id: animal.id,
};
}),
};
},
},
},
});