diff --git a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js index 4636057..249b6b9 100644 --- a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js +++ b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js @@ -13,14 +13,14 @@ const typeDefs = gql` type Author { id: ID! name: String! - married: Boolean! + age: Int! } `; const authors = [ - { id: 1, name: "Terry Pratchett", married: false }, - { id: 2, name: "Stephen King", married: true }, - { id: 3, name: "JK Rowling", married: false } + { id: 1, name: "Terry Pratchett", age: 67 }, + { id: 2, name: "Stephen King", age: 71 }, + { id: 3, name: "JK Rowling", age: 53 } ]; const resolvers = { @@ -35,7 +35,6 @@ const resolvers = { return; }, authorByName: (root, args, context) => { - console.log("hihhihi", args.name); return authors.find(x => x.name === args.name) || "NOTFOUND"; } } diff --git a/src/functions-templates/js/graphql-gateway/graphql-gateway.js b/src/functions-templates/js/graphql-gateway/graphql-gateway.js index f40ac32..8de5ede 100644 --- a/src/functions-templates/js/graphql-gateway/graphql-gateway.js +++ b/src/functions-templates/js/graphql-gateway/graphql-gateway.js @@ -19,40 +19,40 @@ exports.handler = async function(event, context) { const schema2 = await getSchema("graphql-2"); // other Netlify functions which are graphql lambdas const schemas = [schema1, schema2]; - // /** - // * resolving -between- schemas - // * https://www.apollographql.com/docs/graphql-tools/schema-stitching#adding-resolvers - // */ - // const linkTypeDefs = ` - // extend type Book { - // author: Author - // } - // ` - // schemas.push(linkTypeDefs) - // const resolvers = { - // Book: { - // author: { - // fragment: `... on Book { authorName }`, - // resolve(book, args, context, info) { - // return info.mergeInfo.delegateToSchema({ - // schema: schema1, - // operation: "query", - // fieldName: "authorByName", // reuse what's implemented in schema1 - // args: { - // name: book.authorName, - // }, - // context, - // info, - // }) - // }, - // }, - // }, - // } + /** + * resolving -between- schemas + * https://www.apollographql.com/docs/graphql-tools/schema-stitching#adding-resolvers + */ + const linkTypeDefs = ` + extend type Book { + author: Author + } + `; + schemas.push(linkTypeDefs); + const resolvers = { + Book: { + author: { + fragment: `... on Book { authorName }`, + resolve(book, args, context, info) { + return info.mergeInfo.delegateToSchema({ + schema: schema1, + operation: "query", + fieldName: "authorByName", // reuse what's implemented in schema1 + args: { + name: book.authorName + }, + context, + info + }); + } + } + } + }; // more docs https://www.apollographql.com/docs/graphql-tools/schema-stitching#api const schema = mergeSchemas({ - schemas - // ,resolvers + schemas, + resolvers }); const server = new ApolloServer({ schema }); return new Promise((yay, nay) => {