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

Commit

Permalink
add graphql gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-yx committed Apr 10, 2019
1 parent 72d80aa commit 8b294bf
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 714 deletions.
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class DevCommand extends Command {

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

// serve functions from zip-it-and-ship-it
// env variables relies on `url`, careful moving this code
if (functionsDir) {
const functionBuilder = await detectFunctionsBuilder(settings);
if (functionBuilder) {
Expand Down Expand Up @@ -272,6 +274,9 @@ class DevCommand extends Command {
chalk.bold(`${NETLIFYDEVLOG} Server now ready on ${url}`),
70
);
process.env.URL = url;
process.env.DEPLOY_URL = process.env.URL;

this.log(
boxen(banner, {
padding: 1,
Expand Down
24 changes: 24 additions & 0 deletions src/functions-templates/js/apollo-graphql/apollo-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@ const { ApolloServer, gql } = require("apollo-server-lambda");
const typeDefs = gql`
type Query {
hello: String
allAuthors: [Author!]
author(id: Int!): Author
authorByName(name: String!): Author
}
type Author {
id: ID!
name: String!
married: Boolean!
}
`;

const authors = [
{ id: 1, name: "Terry Pratchett", married: false },
{ id: 2, name: "Stephen King", married: true },
{ id: 3, name: "JK Rowling", married: false }
];

const resolvers = {
Query: {
hello: (root, args, context) => {
return "Hello, world!";
},
allAuthors: (root, args, context) => {
return authors;
},
author: (root, args, context) => {
return;
},
authorByName: (root, args, context) => {
console.log("hihhihi", args.name);
return authors.find(x => x.name === args.name) || "NOTFOUND";
}
}
};
Expand Down
Loading

0 comments on commit 8b294bf

Please sign in to comment.