This commit is contained in:
Sean Macfarlane
2020-03-24 13:35:56 -04:00
commit 75befca4d4
6 changed files with 1390 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

1312
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "tip-wlan-graphql-apollo",
"version": "0.1.0",
"description": "",
"main": "index.js",
"dependencies": {
"apollo-server": "^2.11.0",
"graphql": "^14.6.0"
},
"devDependencies": {},
"scripts": {
"start": "node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://sean_macfarlane@bitbucket.org/connectustechnologies/tip-wlan-graphql-apollo.git"
},
"keywords": [],
"author": "",
"license": "MIT",
"homepage": "https://bitbucket.org/connectustechnologies/tip-wlan-graphql-apollo#readme"
}

24
src/index.js Normal file
View File

@@ -0,0 +1,24 @@
const { ApolloServer, gql } = require("apollo-server");
const typeDefs = require("./schema");
const resolvers = require("./resolvers");
const books = [
{
title: "Harry Potter and the Chamber of Secrets",
author: "J.K. Rowling"
},
{
title: "Jurassic Park",
author: "Michael Crichton"
}
];
// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({ typeDefs, resolvers });
// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});

9
src/resolvers.js Normal file
View File

@@ -0,0 +1,9 @@
// Resolvers define the technique for fetching the types defined in the
// schema. This resolver retrieves books from the "books" array above.
const resolvers = {
Query: {
books: () => books
}
};
module.exports = resolvers;

21
src/schema.js Normal file
View File

@@ -0,0 +1,21 @@
// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
// your data.
const typeDefs = gql`
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}
# The "Query" type is special: it lists all of the available queries that
# clients can execute, along with the return type for each. In this
# case, the "books" query returns an array of zero or more Books (defined above).
type Query {
books: [Book]
}
`;
module.exports = typeDefs;