Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props graph syntax #37

Merged
merged 3 commits into from
Sep 19, 2024
Merged

Props graph syntax #37

merged 3 commits into from
Sep 19, 2024

Conversation

tonyspiro
Copy link
Member

@tonyspiro tonyspiro commented Sep 2, 2024

As a user, I want to be able to use props more efficiently, currently it’s cumbersome and confusing for deeply nested props. For context on props, see the Cosmic docs for fetching Objects. For example:

This is not ideal:

const props = 'slug,title,created_at,metadata.author.title,metadata.author.metadata.favorite_places.title,metadata.author.metadata.favorite_places.metadata.image.url,metadata.vehicle.title,metadata.vehicle.created_at,metadata.vehicle.metadata.image.url'

const { object } = await cosmic.objects.findOne({
  type: "articles",
  slug: "lets-goo"
}).props(props)
.depth(3)

It would be better to have something like this:

const props = `{
  slug
  title
  created_at
  metadata {
    author {
      title
      metadata {
        favorite_places {
          title
          metadata {
            image {
              url
            }
          }
        }
      }
    }
    vehicle {
      title
      created_at
      metadata {
        image {
          url
        }
      }
    }
  }
}`

const { object } = await cosmic.objects.findOne({
  type: "articles",
  slug: "lets-goo"
}).props(props).depth(3)

This will give you the explicit shape of the data payload.

@tonyspiro tonyspiro changed the title RFC: props graph syntax Props graph syntax Sep 17, 2024
@tonyspiro tonyspiro marked this pull request as ready for review September 17, 2024 16:26
@tonyspiro tonyspiro merged commit 79571fe into main Sep 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant