Implementation:
-
Interface and union types for polymorphic data:
graphql
interface Product { id: ID! name: String! price: Float! } type Book implements Product { id: ID! name: String! price: Float! author: String! pages: Int! } union SearchResult = Book | Author | Publisher
-
Schema stitching for microservices:
javascript
const { stitchSchemas } = require('@graphql-tools/stitch'); const gatewaySchema = stitchSchemas({ subschemas: [ { schema: await loadRemoteSchema('http://products-service/graphql'), merge: { Product: { selectionSet: '{ id }', fieldName: 'product', args: (originalResult) => ({ id: originalResult.id }), } } } ] });