-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from basehub-ai/jb/support-fragmentOf
support fragmentOf
- Loading branch information
Showing
7 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
"basehub": major | ||
"playground": patch | ||
--- | ||
|
||
# New `fragmentOn` helper to extract fragments | ||
|
||
In this new major version, we're introducing `fragmentOn`, a simpler way to create fragments in the `basehub` SDK. | ||
|
||
Previously, in order to reuse a fragment, you'd do something like this: | ||
|
||
```ts | ||
// old way 👎 | ||
import { LinkComponentGenqlSelection, LinkComponent, FieldsSelection } from 'basehub' | ||
|
||
const LinkFragment = { | ||
href: true, | ||
label: true | ||
} satisfies LinkComponentGenqlSelection | ||
|
||
// extract the type | ||
type LinkFragment = FieldsSelection<LinkComponent, typeof LinkFragment> | ||
``` | ||
Looks simple, but it's a bit hard to understand. You need to know that we're exposing a `LinkComponentGenqlSelection`, and that you should use the `satisfies` so the object's type is constrained but also can be more specific. Then, to extract the type, you'd get `FieldsSelection`, and finally, `LinkComponent`. A lot of types! | ||
Moreover, if you needed to create another fragment, it'd be this same process, over and over again. | ||
This is how it's done in the new version: | ||
```ts | ||
// new way 👍 | ||
import { fragmentOn } from 'basehub' | ||
|
||
const LinkFragment = fragmentOn("LinkComponent", { | ||
href: true, | ||
label: true | ||
}) | ||
|
||
// extract the type | ||
type LinkFragment = fragmentOn.infer<typeof LinkFragment> | ||
``` | ||
Much simpler! | ||
## Why is this a breaking change | ||
Before this version, we exposed a lot of the internal types from `'basehub'`. We now don't. Some applications might depend on this, and that's why this is a breaking change. If you need those types for some reason that wasn't discussed in this document, feel free to raise an issue and we can see to bring them back. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.