Skip to content

Commit

Permalink
FireStoreからデータを取得する処理を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
keinuma committed Jan 2, 2020
1 parent 2dd7692 commit de84196
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
import { ApolloServer, gql } from "apollo-server-cloud-functions";
import { ApolloServer } from "apollo-server-cloud-functions";
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import "firebase-functions";

import typeDefs from "@/schema";

admin.initializeApp();

const typeDefs = gql`
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;

const books = [
{
title: "Harry Potter and the Chamber of Secrets",
author: "J.K. Rowling"
},
{
title: "Jurassic Park",
author: "Michael Crichton"
}
];
const db = admin.firestore();

const resolvers = {
Query: {
books: () => books
latestMovies: async () => {
const snapshot = await db
.collection("movies")
.orderBy("info.release_date", "desc")
.limit(10)
.get();
console.log(snapshot);
return snapshot.docs.map(doc => {
return doc.data();
});
}
}
};

Expand Down

0 comments on commit de84196

Please sign in to comment.