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

Add snippets for Querying Cheatsheet #3939

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bwreid
Copy link

@bwreid bwreid commented Feb 27, 2025

Description

Adds snippets to be used within the Querying Cheatsheet doc. The only files that will be linked within the docs are the ones within the queries/ directory -- not the querying-cheatsheet/index.tsx file.

As this if my first commit to this repo, please let me know if I've gotten anything wrong! 🙏

- Gen 1 React
- Gen 2 React
Copy link

changeset-bot bot commented Feb 27, 2025

⚠️ No Changeset found

Latest commit: c8aa9e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

gitguardian bot commented Feb 27, 2025

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link

nx-cloud bot commented Feb 27, 2025

View your CI Pipeline Execution ↗ for commit c8aa9e8.

Command Status Duration Result
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 7m 39s View ↗
nx test @e2e/qwik-city ✅ Succeeded 7m 33s View ↗
nx test @e2e/nuxt ✅ Succeeded 6m 57s View ↗
nx test @e2e/angular-16 ✅ Succeeded 6m 15s View ↗
nx test @e2e/gen1-next15-app ✅ Succeeded 6m 13s View ↗
nx test @e2e/angular-16-ssr ✅ Succeeded 6m 12s View ↗
nx test @e2e/react-sdk-next-15-app ✅ Succeeded 5m 37s View ↗
nx test @e2e/angular-19-ssr ✅ Succeeded 5m 34s View ↗
Additional runs (36) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-03-03 19:45:06 UTC

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we need styles for querying cheatsheet docs.

Copy link
Contributor

@uttej-vsk uttej-vsk Feb 28, 2025

Choose a reason for hiding this comment

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

@bwreid The goal is to add only the bare minimum of things you will use in the docs. If you believe that any file that would not break your code or tests, you can safely remove it.

Comment on lines 1 to 11
import { fetchOneEntry } from '@builder.io/sdk-react';

export const getProduct = async (options: {
apiKey: string;
[key: string]: unknown;
}) =>
fetchOneEntry({
model: 'product',
query: { 'data.price': { $gte: 700 } },
...options,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

you should rely on GetContentOptions instead of unknown to let types flow from the SDK

Suggested change
import { fetchOneEntry } from '@builder.io/sdk-react';
export const getProduct = async (options: {
apiKey: string;
[key: string]: unknown;
}) =>
fetchOneEntry({
model: 'product',
query: { 'data.price': { $gte: 700 } },
...options,
});
import { fetchOneEntry, GetContentOptions } from '@builder.io/sdk-react';
const getProduct = async (options: GetContentOptions) =>
fetchOneEntry({
query: { 'data.price': { $gte: 700 } },
...options,
});

same applies to gen1 SDK (remove unknown). You'll have to rework the logic a bit to provide model from the component for your tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the async are redundant here and can be removed. They are only useful if you use await in the body.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @samijaber. Those changes have been made -- please let me know if you have any other thoughts!

- Rely on GetContentOptions for Gen 2 React
- Remove unnecessary `async` keywords
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.

3 participants