Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
update the graphql gateway template
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-yx committed May 14, 2019
1 parent 8787181 commit 04f7bc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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";
}
}
Expand Down
62 changes: 31 additions & 31 deletions src/functions-templates/js/graphql-gateway/graphql-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 04f7bc6

Please sign in to comment.