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

Commit 8b294bf

Browse files
author
sw-yx
committed
add graphql gateway
1 parent 72d80aa commit 8b294bf

File tree

7 files changed

+159
-714
lines changed

7 files changed

+159
-714
lines changed

package-lock.json

+30-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/dev/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class DevCommand extends Command {
222222

223223
startDevServer(settings, this.log, this.error);
224224

225+
// serve functions from zip-it-and-ship-it
226+
// env variables relies on `url`, careful moving this code
225227
if (functionsDir) {
226228
const functionBuilder = await detectFunctionsBuilder(settings);
227229
if (functionBuilder) {
@@ -272,6 +274,9 @@ class DevCommand extends Command {
272274
chalk.bold(`${NETLIFYDEVLOG} Server now ready on ${url}`),
273275
70
274276
);
277+
process.env.URL = url;
278+
process.env.DEPLOY_URL = process.env.URL;
279+
275280
this.log(
276281
boxen(banner, {
277282
padding: 1,

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

+24
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@ const { ApolloServer, gql } = require("apollo-server-lambda");
33
const typeDefs = gql`
44
type Query {
55
hello: String
6+
allAuthors: [Author!]
7+
author(id: Int!): Author
8+
authorByName(name: String!): Author
9+
}
10+
type Author {
11+
id: ID!
12+
name: String!
13+
married: Boolean!
614
}
715
`;
816

17+
const authors = [
18+
{ id: 1, name: "Terry Pratchett", married: false },
19+
{ id: 2, name: "Stephen King", married: true },
20+
{ id: 3, name: "JK Rowling", married: false }
21+
];
22+
923
const resolvers = {
1024
Query: {
1125
hello: (root, args, context) => {
1226
return "Hello, world!";
27+
},
28+
allAuthors: (root, args, context) => {
29+
return authors;
30+
},
31+
author: (root, args, context) => {
32+
return;
33+
},
34+
authorByName: (root, args, context) => {
35+
console.log("hihhihi", args.name);
36+
return authors.find(x => x.name === args.name) || "NOTFOUND";
1337
}
1438
}
1539
};

0 commit comments

Comments
 (0)