GraphQL collections (#1536)

This commit is contained in:
Isha Gupta
2021-03-18 20:25:12 +05:30
committed by GitHub
parent 942b86c647
commit e565f9bf72
27 changed files with 2035 additions and 89 deletions

View File

@@ -1108,7 +1108,7 @@ describe("FirebaseInstance", () => {
signInUser()
await expect(fb.writeCollections([])).resolves.toBeUndefined()
await expect(fb.writeCollections([], "collections")).resolves.toBeUndefined()
})
test("rejects for non-authenticated request", async () => {
@@ -1116,7 +1116,7 @@ describe("FirebaseInstance", () => {
signOutUser()
await expect(fb.writeCollections([])).rejects.toBeDefined()
await expect(fb.writeCollections([], "collections")).rejects.toBeDefined()
})
test("stores data on firestore with proper structure", async () => {
@@ -1124,7 +1124,7 @@ describe("FirebaseInstance", () => {
signInUser()
await fb.writeCollections([])
await fb.writeCollections([], "collections")
const doc = (
await mocksdk
@@ -1152,7 +1152,7 @@ describe("FirebaseInstance", () => {
signInUser()
await fb.writeCollections([])
await fb.writeCollections([], "collections")
const doc = (
await mocksdk

View File

@@ -35,6 +35,7 @@ export class FirebaseInstance {
this.currentHistory = []
this.currentGraphqlHistory = []
this.currentCollections = []
this.currentGraphqlCollections = []
this.currentEnvironments = []
this.app.auth().onAuthStateChanged((user) => {
@@ -133,6 +134,21 @@ export class FirebaseInstance {
}
})
this.usersCollection
.doc(this.currentUser.uid)
.collection("collectionsGraphql")
.onSnapshot((collectionsRef) => {
const collections = []
collectionsRef.forEach((doc) => {
const collection = doc.data()
collection.id = doc.id
collections.push(collection)
})
if (collections.length > 0) {
this.currentGraphqlCollections = collections[0].collection
}
})
this.usersCollection
.doc(this.currentUser.uid)
.collection("environments")
@@ -319,7 +335,7 @@ export class FirebaseInstance {
}
}
async writeCollections(collection) {
async writeCollections(collection, flag) {
const cl = {
updatedOn: new Date(),
author: this.currentUser.uid,
@@ -329,11 +345,7 @@ export class FirebaseInstance {
}
try {
await this.usersCollection
.doc(this.currentUser.uid)
.collection("collections")
.doc("sync")
.set(cl)
await this.usersCollection.doc(this.currentUser.uid).collection(flag).doc("sync").set(cl)
} catch (e) {
console.error("error updating", cl, e)