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

Commit 8454a52

Browse files
author
sw-yx
committed
add small example file
1 parent c3ad69b commit 8454a52

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// not meant to be run inside the graqhql-gateway function
2+
// but just shows a copy-pastable example sibling function
3+
// that would work with graphql-gateway
4+
const { ApolloServer, gql } = require("apollo-server-lambda");
5+
6+
const typeDefs = gql`
7+
type Query {
8+
hello: String
9+
allAuthors: [Author!]
10+
author(id: Int!): Author
11+
authorByName(name: String!): Author
12+
}
13+
type Author {
14+
id: ID!
15+
name: String!
16+
married: Boolean!
17+
}
18+
`;
19+
20+
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 }
24+
];
25+
26+
const resolvers = {
27+
Query: {
28+
hello: (root, args, context) => {
29+
return "Hello, world!";
30+
},
31+
allAuthors: (root, args, context) => {
32+
return authors;
33+
},
34+
author: (root, args, context) => {
35+
return;
36+
},
37+
authorByName: (root, args, context) => {
38+
console.log("hihhihi", args.name);
39+
return authors.find(x => x.name === args.name) || "NOTFOUND";
40+
}
41+
}
42+
};
43+
44+
const server = new ApolloServer({
45+
typeDefs,
46+
resolvers
47+
});
48+
49+
exports.handler = server.createHandler();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// not meant to be run inside the graqhql-gateway function
2+
// but just shows a copy-pastable example sibling function
3+
// that would work with graphql-gateway
4+
const { ApolloServer, gql } = require("apollo-server-lambda");
5+
6+
const typeDefs = gql`
7+
type Query {
8+
hello: String
9+
allBooks: [Book]
10+
book(id: Int!): Book
11+
}
12+
type Book {
13+
id: ID!
14+
year: Int!
15+
title: String!
16+
authorName: String!
17+
}
18+
`;
19+
20+
const books = [
21+
{
22+
id: 1,
23+
title: "The Philosopher's Stone",
24+
year: 1997,
25+
authorName: "JK Rowling"
26+
},
27+
{
28+
id: 2,
29+
title: "The Chamber of Secrets",
30+
year: 1998,
31+
authorName: "Stephen King"
32+
},
33+
{
34+
id: 3,
35+
title: "The Prisoner of Azkaban",
36+
year: 1999,
37+
authorName: "Terry Pratchett"
38+
},
39+
{
40+
id: 4,
41+
title: "The Goblet of Fire",
42+
year: 2000,
43+
authorName: "Terry Pratchett"
44+
},
45+
{
46+
id: 5,
47+
title: "The Order of the Phoenix",
48+
year: 2003,
49+
authorName: "Terry Pratchett"
50+
},
51+
{
52+
id: 6,
53+
title: "The Half-Blood Prince",
54+
year: 2005,
55+
authorName: "Stephen King"
56+
},
57+
{
58+
id: 7,
59+
title: "The Deathly Hallows",
60+
year: 2007,
61+
authorName: "Stephen King"
62+
}
63+
];
64+
65+
const resolvers = {
66+
Query: {
67+
hello: (root, args, context) => {
68+
return "Hello, world!";
69+
},
70+
allBooks: (root, args, context) => {
71+
return books;
72+
},
73+
book: (root, args, context) => {
74+
return find(books, { id: args.id });
75+
}
76+
}
77+
};
78+
79+
const server = new ApolloServer({
80+
typeDefs,
81+
resolvers
82+
});
83+
84+
exports.handler = server.createHandler();

0 commit comments

Comments
 (0)