question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Firestore sub-collections

See original GitHub issue

Is your feature request related to a problem? Please describe. It is unclear at this time how to use firestore subcollections with @gqlify/firestore.

Describe the solution you’d like I imagine creating the type like so:

type Book @GQLifyModel(dataSource: "firestore", key: "books") {
  id: ID! @unique @autoGen
  title: String!
  author: Author!
}

type Author @GQLifyModel(dataSource: "firestore", key: "books/*/authors") {
  id: ID! @unique @autoGen
  name: String!
}

and then updating or creating a field requires a where params list like so:

type AuthorWhereUniqueInupt {
  bookId: ID!
  authorId: ID!
}

or could we use a Firestore sub-collection specific where param where the id field is the document path? Eg:

type AuthorWhereUniqueInupt {
  parentPath: String!
  authorId: ID!
}

where the parentPath is more like the current path usage in Firestore SDK:

variables = {
  parentPath: `books/${someBookId}`
}

Issues with this solution:

  • how do we query sub-collections?
  • what syntax do we use to represent the document in the collection/document/collection path key? That is, does books/*/authors work well enough?

Describe alternatives you’ve considered Using root-level Firestore collections is a viable alternative since relationships/foreign-keys are already supported. There are performance implications with doing so though where sub-collections would be desirable.

Additional context Just starting a discussion of the idea 😄

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
wwwy3y3commented, Jan 30, 2019

@jthegedus We’re always glad to hear thoughts from the community 😄

Please don’t hesitate to share your thoughts.

Hope to hear more from you when we release Canner v3 in a few days later.

1reaction
jthegeduscommented, Jan 30, 2019

@wwwy3y3 I agree completely, just wanted to raise the thoughts.

I think createSubResource(path: string, input: Input) is a great solution should it become a heavily requested feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Firestore Data model - Firebase
Subcollections allow you to structure data hierarchically, making data easier to access. To get all messages in roomA , you can create a...
Read more >
Create a Firestore subcollection reference - Google Cloud
Stay organized with collections Save and categorize content based on your preferences.
Read more >
Firestore query subcollections - firebase - Stack Overflow
Single queries across multiple collections or subcollections. Each query runs against a single collection of documents. For more information ...
Read more >
Firestore Subcollections In Flutter | by Anmol Gupta - FlutterDevs
Table of content: ::What is subcollection? ... To work with firebase cloud firestore in flutter you need to learn about basic crud operation...
Read more >
How to list all subcollections of a Cloud Firestore document?
As detailed in the Cloud Firestore documentation, data in Firestore is stored into documents, which are “organized into collections”. Documents ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found