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

Commit 04f7bc6

Browse files
author
sw-yx
committed
update the graphql gateway template
1 parent 8787181 commit 04f7bc6

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const typeDefs = gql`
1313
type Author {
1414
id: ID!
1515
name: String!
16-
married: Boolean!
16+
age: Int!
1717
}
1818
`;
1919

2020
const authors = [
21-
{ id: 1, name: "Terry Pratchett", married: false },
22-
{ id: 2, name: "Stephen King", married: true },
23-
{ id: 3, name: "JK Rowling", married: false }
21+
{ id: 1, name: "Terry Pratchett", age: 67 },
22+
{ id: 2, name: "Stephen King", age: 71 },
23+
{ id: 3, name: "JK Rowling", age: 53 }
2424
];
2525

2626
const resolvers = {
@@ -35,7 +35,6 @@ const resolvers = {
3535
return;
3636
},
3737
authorByName: (root, args, context) => {
38-
console.log("hihhihi", args.name);
3938
return authors.find(x => x.name === args.name) || "NOTFOUND";
4039
}
4140
}

src/functions-templates/js/graphql-gateway/graphql-gateway.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,40 @@ exports.handler = async function(event, context) {
1919
const schema2 = await getSchema("graphql-2"); // other Netlify functions which are graphql lambdas
2020
const schemas = [schema1, schema2];
2121

22-
// /**
23-
// * resolving -between- schemas
24-
// * https://www.apollographql.com/docs/graphql-tools/schema-stitching#adding-resolvers
25-
// */
26-
// const linkTypeDefs = `
27-
// extend type Book {
28-
// author: Author
29-
// }
30-
// `
31-
// schemas.push(linkTypeDefs)
32-
// const resolvers = {
33-
// Book: {
34-
// author: {
35-
// fragment: `... on Book { authorName }`,
36-
// resolve(book, args, context, info) {
37-
// return info.mergeInfo.delegateToSchema({
38-
// schema: schema1,
39-
// operation: "query",
40-
// fieldName: "authorByName", // reuse what's implemented in schema1
41-
// args: {
42-
// name: book.authorName,
43-
// },
44-
// context,
45-
// info,
46-
// })
47-
// },
48-
// },
49-
// },
50-
// }
22+
/**
23+
* resolving -between- schemas
24+
* https://www.apollographql.com/docs/graphql-tools/schema-stitching#adding-resolvers
25+
*/
26+
const linkTypeDefs = `
27+
extend type Book {
28+
author: Author
29+
}
30+
`;
31+
schemas.push(linkTypeDefs);
32+
const resolvers = {
33+
Book: {
34+
author: {
35+
fragment: `... on Book { authorName }`,
36+
resolve(book, args, context, info) {
37+
return info.mergeInfo.delegateToSchema({
38+
schema: schema1,
39+
operation: "query",
40+
fieldName: "authorByName", // reuse what's implemented in schema1
41+
args: {
42+
name: book.authorName
43+
},
44+
context,
45+
info
46+
});
47+
}
48+
}
49+
}
50+
};
5151

5252
// more docs https://www.apollographql.com/docs/graphql-tools/schema-stitching#api
5353
const schema = mergeSchemas({
54-
schemas
55-
// ,resolvers
54+
schemas,
55+
resolvers
5656
});
5757
const server = new ApolloServer({ schema });
5858
return new Promise((yay, nay) => {

0 commit comments

Comments
 (0)