watermarkchurch / wcc-contentful

An alternative to Contentful's contentful.rb ruby client, contentful_model, and contentful_rails gems all in one.
MIT License
2 stars 1 forks source link

adds ability to nest CDN query conditions #32

Closed jpowell closed 6 years ago

jpowell commented 6 years ago

closes #30

jpowell commented 6 years ago

@gburgett still a WIP. Some things need to move around and be cleaned up / consolidated, but have the basis for moving forward.

jpowell commented 6 years ago

Question on dev interface. We could go a couple different routes here. Both have their benefits.

# Option A (in this PR)
# Pro: treats all fields the same in interface, hides contentful semantics
# Con: makes assumptions about data structure and prevents using fields that may collide with "reserved" keywords in sys (id, space, contentType, etc)
Page.find_by(subpages: { id: '1324asdfadsf' })

# Option B
# Pro:
#  - simplifies implementation and assumptions to make on query arguments 
#  - explicit reflection of contentful's underlying semantics
# Con: must pass full representation for queries
Page.find_by('fields.subpages' => { 'sys.id' => '1234adfasdf' })

# Option C
# Pro:
#  - combine the above, allows for simplified querying and allows for using sys fields in your model
#  - simplifies implementation and assumptions to make on query arguments 
# Con: must prefix reserved keywords (sys) with `_` and know which fields to do so with
Page.find_by(subpages: { _id: '1234asdffsdf' })
gburgett commented 6 years ago

I definitely think the most common case needs to be most convenient, i.e.:

Page.find_by(slug: 'asdf')

I can get behind supporting option A, if we did it this way on conflicts:

# {
#    "sys": { "space": { "sys": { "id": "1xab" } } },
#    "fields": [
#      "space": { "en-US": "foo" }
#    ] 
# }

# Finds by the field named "space":
Page.find_by(space: "foo")

# Finds by the space with ID "1xab"
Page.find_by('sys.space.sys.id' => '1xab')

i.e. if the content type has a field named "space" that takes precedence. Of course that would require the query builder to know the content type which may make this undesirable.

My favorite is option C so far