Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ interface User {
interface Tweet {
id: string;
name: string;
screenName: string;
statusesCount: number;
text: string;
likes: number;
userId: string;
}
```
Expand Down Expand Up @@ -120,6 +120,7 @@ const typeDefs = gql`
type Query {
tweets: [Tweets]
user(id: String!): User
users: [User]
}
`;
```
Expand Down Expand Up @@ -153,6 +154,13 @@ const resolvers = {
} catch (error) {
throw new ApolloError(error);
}
},
async users() {
const users = await admin
.firestore()
.collection('users')
.get();
return users.docs.map(user => user.data()) as User[];
}
}
};
Expand Down
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const typeDefs = gql`
name: String!
screenName: String!
statusesCount: Int!
tweets: [Tweets]!
tweets: [Tweet]!
}

# A Tweet Object
type Tweets {
type Tweet {
id: ID!
text: String!
userId: String!
Expand All @@ -42,8 +42,9 @@ const typeDefs = gql`
}

type Query {
tweets: [Tweets]
tweets: [Tweet]
user(id: String!): User
users: [User]
}
`;

Expand All @@ -67,6 +68,13 @@ const resolvers = {
} catch (error) {
throw new ApolloError(error);
}
},
async users() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this in a try catch block like the queries?

const users = await admin
.firestore()
.collection('users')
.get();
return users.docs.map(user => user.data()) as User[];
}
},
User: {
Expand All @@ -83,7 +91,7 @@ const resolvers = {
}
}
},
Tweets: {
Tweet: {
async user(tweet) {
try {
const tweetAuthor = await admin
Expand Down