@tinacms/graphql 0.60.7 → 0.61.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md DELETED
@@ -1,1142 +0,0 @@
1
- # tina-graphql
2
-
3
- ## 0.60.7
4
-
5
- ### Patch Changes
6
-
7
- - f6cb634c2: Added an optional config key to the schema that will be used for tina cloud media store
8
- - b1a4290e6: Use media config from the schema in the local media server
9
- - 1955b8842: Uses new `schema.config` when resolving media/asset urls
10
- - 8b81c3cf3: Added more context to error messages to help to user debug issues
11
- - @tinacms/datalayer@0.1.1
12
-
13
- ## 0.60.6
14
-
15
- ### Patch Changes
16
-
17
- - e2aafcd93: Add more GraphQL variables to the generated queries.
18
- - a20fed8b7: Resolve Cloud URLs to Relative URLs when saving TinaCloud's media
19
-
20
- Introduces a pair of functions (inside `media-utils.ts`) for handling URLs provided by TinaCloud (`resolveMediaCloudToRelative` and `resolveMediaRelativeToCloud`).
21
-
22
- These are used in conjuction with two pairs of functions:
23
-
24
- - When providing data to the preview: `resolveFieldData` and `parseMDX`
25
- - When saving data to the document: `buildFieldMutations` and `stringifyMDX`
26
-
27
- I also introduced tests around `media-utils.ts` (`media-utils.test.ts`).
28
-
29
- ## 0.60.5
30
-
31
- ### Patch Changes
32
-
33
- - 57f09bdd7: Always use the query function when the dataLayer in enabled
34
-
35
- ## 0.60.4
36
-
37
- ### Patch Changes
38
-
39
- - d103b27ad: Fix issue where new collections would not be added when CLI restarts
40
-
41
- ## 0.60.3
42
-
43
- ### Patch Changes
44
-
45
- - 79d112d79: Update cli to accept tinaCloudMediaStore flag and add to metadata during schema compilation
46
- - 3f46c6706: Fixed issue where generated SDK would not work with templates
47
- - db9168578: Adds support for an `assetsHost` when resolving `image` fields with `useRelativeMedia`
48
- - 91d6e6758: Fix issues with experimentalData on windows related to path separator inconsistency and interference with the .tina/**generated** folder
49
-
50
- ## 0.60.2
51
-
52
- ### Patch Changes
53
-
54
- - 08cdb672a: Adds `useRelativeMedia` support to local graphql client
55
- - fdbfe9a16: Fixes issue where on windows documents could not be deleted localy
56
- - 6e2ed31a2: Added `isTitle` property to the schema that allows the title to be displayed in the CMS
57
-
58
- ## 0.60.1
59
-
60
- ### Patch Changes
61
-
62
- - 3b11ff6ad: Add optional indexing status callback to Database
63
-
64
- ## 0.60.0
65
-
66
- ### Minor Changes
67
-
68
- - 6a6f137ae: # Simplify GraphQL API
69
-
70
- ## `schema` must be supplied to the `<TinaCMS>` component
71
-
72
- Previously the `.tina/schema.ts` was only used by the Tina CLI to generate the GraphQL API. However it's now required as a prop to `<TinaCMS>`. This allows you to provide runtime logic in the `ui` property of field definitions. See the documentation on "Extending Tina" for examples.
73
-
74
- ## The GraphQL API has been simplified
75
-
76
- ### `get<collection name>` is now just the collection name
77
-
78
- ```graphql
79
- # old
80
- {
81
- getPostDocument(relativePath: $relativePath) { ... }
82
- }
83
-
84
- # new
85
- {
86
- post(relativePath: $relativePath) { ... }
87
- }
88
- ```
89
-
90
- ### `get<collection name>List` is now `<collection name>Connection`
91
-
92
- The use of the term `connection` is due to our adherence the the [relay cursor spec](https://relay.dev/graphql/connections.htm). We may offer a simplified list field in a future release
93
-
94
- ```graphql
95
- # old
96
- {
97
- getPostList { ... }
98
- }
99
-
100
- # new
101
- {
102
- postConnection { ... }
103
- }
104
- ```
105
-
106
- ### `getCollection` and `getCollections` are now `collection` and `collections`
107
-
108
- ```graphql
109
- # old
110
- {
111
- getCollection(collection: "post") {...}
112
- }
113
- {
114
- getCollections {...}
115
- }
116
-
117
- # new
118
- {
119
- collection(collection: "post") {...}
120
- }
121
- {
122
- collections {...}
123
- }
124
- ```
125
-
126
- ### No more `data` property
127
-
128
- The `data` property was previously where all field definitions could be found. This has been moved on level up:
129
-
130
- ```graphql
131
- # old
132
- {
133
- getPostDocument(relativePath: $relativePath) {
134
- data {
135
- title
136
- }
137
- }
138
- }
139
-
140
- # new
141
- {
142
- post(relativePath: $relativePath) {
143
- title
144
- }
145
- }
146
- ```
147
-
148
- #### The type for documents no longer includes "Document" at the end
149
-
150
- ```graphql
151
- # old
152
- {
153
- getPostDocument(relativePath: $relativePath) {
154
- data {
155
- author {
156
- ... on AuthorDocument {
157
- data {
158
- name
159
- }
160
- }
161
- }
162
- }
163
- }
164
- }
165
-
166
- # new
167
- {
168
- post(relativePath: $relativePath) {
169
- author {
170
- ... on Author {
171
- name
172
- }
173
- }
174
- }
175
- }
176
- ```
177
-
178
- ### Meta fields are now underscored
179
-
180
- Aside from `id`, other metadata is now underscored:
181
-
182
- ```graphql
183
- # old
184
- {
185
- getPostDocument(relativePath: $relativePath) {
186
- sys {
187
- relativePath
188
- }
189
- values
190
- }
191
- }
192
-
193
- # new
194
- {
195
- post(relativePath: $relativePath) {
196
- _sys {
197
- relativePath
198
- }
199
- _values
200
- }
201
- }
202
- ```
203
-
204
- ### `dataJSON` is gone
205
-
206
- This is identical to `_values`
207
-
208
- ### `form` is gone
209
-
210
- `form` was used internally to generate forms for the given document, however that's now handled by providing your `schema` to `<TinaCMS>`.
211
-
212
- ### `getDocumentList` is gone
213
-
214
- It's no longer possible to query all documents at once, you can query for collection documents via the `collection` query:
215
-
216
- ```graphql
217
- {
218
- collection {
219
- documents {
220
- edges {
221
- node {...}
222
- }
223
- }
224
- }
225
- }
226
- ```
227
-
228
- ## 0.59.11
229
-
230
- ### Patch Changes
231
-
232
- - 4da32454b: Modify database to write config json files without whitespace to reduce file sizes
233
- - 921709a7e: Adds validation to the schema instead of only using typescript types
234
- - 558cc4368: Make schema init platform-aware and refactor database put requests
235
- - 06666d39f: Link to MDX documentation when unregistered component error occurs
236
- - 3e2d9e43a: Adds new GraphQL `deleteDocument` mutation and logic
237
- - Updated dependencies [a2906d6fe]
238
- - Updated dependencies [3e2d9e43a]
239
- - @tinacms/datalayer@0.1.1
240
-
241
- ## 0.59.10
242
-
243
- ### Patch Changes
244
-
245
- - cf33bcec1: Fix issue where store.clear() was not being awaited causing an invalid state after reindex
246
-
247
- ## 0.59.9
248
-
249
- ### Patch Changes
250
-
251
- - 82174ff50: Modify Database.indexContentByPaths to not require collection parameter
252
- - a87e1e6fa: Enable query filtering, pagination, sorting
253
- - abf25c673: The schema can now to used on the frontend (optional for now but will be the main path moving forward).
254
-
255
- ### How to migrate.
256
-
257
- If you gone though the `tinacms init` process there should be a file called `.tina/components/TinaProvider`. In that file you can import the schema from `schema.ts` and add it to the TinaCMS wrapper component.
258
-
259
- ```tsx
260
- import TinaCMS from 'tinacms'
261
- import schema, { tinaConfig } from '../schema.ts'
262
-
263
- // Importing the TinaProvider directly into your page will cause Tina to be added to the production bundle.
264
- // Instead, import the tina/provider/index default export to have it dynamially imported in edit-moode
265
- /**
266
- *
267
- * @private Do not import this directly, please import the dynamic provider instead
268
- */
269
- const TinaProvider = ({ children }) => {
270
- return (
271
- <TinaCMS {...tinaConfig} schema={schema}>
272
- {children}
273
- </TinaCMS>
274
- )
275
- }
276
-
277
- export default TinaProvider
278
- ```
279
-
280
- - 591640db0: Fixes a bug with `breadcrumbs` to account for subfolders (instead of just the `filename`) and allows Documents to be created and updated within subfolders.
281
-
282
- Before this fix, `breadcrumbs` was only the `basename` of the file minus the `extension`. So `my-folder-a/my-folder-b/my-file.md` would have `breadcrumbs` of `['my-file']`. With this change, `breadcrumbs` will be `['my-folder-a','my-folder-b','my-file']` (leaving out the `content/<collection>`).
283
-
284
- - e8b0de1f7: Add `parentTypename` to fields to allow us to disambiguate between fields which have the same field names but different types. Example, an event from field name of `blocks.0.title` could belong to a `Cta` block or a `Hero` block, both of which have a `title` field.
285
- - Updated dependencies [8b3be903f]
286
- - Updated dependencies [a87e1e6fa]
287
- - Updated dependencies [b01f2e382]
288
- - @tinacms/datalayer@0.1.0
289
-
290
- ## 0.59.8
291
-
292
- ### Patch Changes
293
-
294
- - e7b27ba3b: Fix issue where un-normalized rich-text fields which send `null` values to the server on save would cause a parsing error
295
- - 11d55f441: Add experimental useGraphQLForms hook
296
-
297
- ## 0.59.7
298
-
299
- ### Patch Changes
300
-
301
- - c730fa1dd: fix: #1452: update indexDocument to handle adding new docs
302
- - cd0f6f022: Do not resolve all documents in `getCollection` if it is not needed
303
-
304
- ## 0.59.6
305
-
306
- ### Patch Changes
307
-
308
- - b399c734c: Fixes support for collection.templates in graphql
309
-
310
- ## 0.59.5
311
-
312
- ### Patch Changes
313
-
314
- - 8ad8f03fd: Select field now validates when required is true.
315
- - 04b7988d5: Some updates to the data layer POC work
316
- - Don't attempt to put config files on to bridge if it's not supported
317
- - Split logic for indexing all content vs a subset of files
318
- - e3c41f69d: Fixed type for `required: true` on `type: "object"`
319
- - f5390e841: Don't attempt to put config files on to bridge if it's not supported
320
- - 32082e0b3: GraphQL number type is changed from "Int" to "Float"
321
-
322
- ## 0.59.4
323
-
324
- ### Patch Changes
325
-
326
- - b66aefde1: Fixed issue where one could not add a title and then a bold text
327
- - 35884152b: Adds and audit command that checks files for errors.
328
- - 4948beec6: Fix issues with mdx code blocks and inline code nodes
329
-
330
- ## 0.59.3
331
-
332
- ### Patch Changes
333
-
334
- - 34cd3a44a: Fix issue where frontmatter parser would return a Date object which would be cast to epoch format
335
- - b006a5ab9: Added delete button to image field
336
- - a324b9c37: Export utilities for working with the data layer
337
- - 80732bd97: Create a @tinacms/datalayer package which houses the logic for data management for the GraphQL API. This simplifies the @tinacms/graphql package and allows for a clearer separation.
338
- - 0bec208e2: validate the schema for `path` and `matches`
339
- - 5c070a83f: feat: Add UI banner for when in localMode
340
-
341
- ## 0.59.2
342
-
343
- ### Patch Changes
344
-
345
- - 212685fc3: Allow indexDB to skip building the query and fragment generation files
346
-
347
- ## 0.59.1
348
-
349
- ### Patch Changes
350
-
351
- - f46c6f987: Fix type definitions for schema metadata so they're optional
352
-
353
- ## 0.59.0
354
-
355
- ### Minor Changes
356
-
357
- - 62bea7019: #2323: fix saving bold and italic text in rich-text editor
358
-
359
- ### Patch Changes
360
-
361
- - bd4e1f802: Pin version number from @tinacms/graphql during schema compilation. This can be used to ensure the proper version is provided when working with Tina Cloud
362
-
363
- ## 0.58.2
364
-
365
- ### Patch Changes
366
-
367
- - fffce3af8: Don't cache graphql schema during resolution, this was causing the schema to go stale, while updating the schema.gql, so GraphQL tooling thought the value was updated, but the server was still holding on to the cached version
368
-
369
- ## 0.58.1
370
-
371
- ### Patch Changes
372
-
373
- - 4700d7ae4: Patch fix to ensure builds include latest dependencies
374
-
375
- ## 0.58.0
376
-
377
- ### Minor Changes
378
-
379
- - fa7a0419f: Adds experimental support for a data layer between file-based content and the GraphQL API. This allows documents to be indexed so the CMS can behave more like a traditional CMS, with the ability enforce foreign reference constraints and filtering/pagination capabilities.
380
-
381
- ### Patch Changes
382
-
383
- - eb5fbfac7: Ensure GraphQL resolve doesn't access "bridge" documents
384
- - 47d126029: Fix support of objects in a list for MDX templates
385
-
386
- ## 0.57.2
387
-
388
- ### Patch Changes
389
-
390
- - edb2f4011: Trim path property on collections during compilation
391
-
392
- ## 0.57.1
393
-
394
- ### Patch Changes
395
-
396
- - 60729f60c: Adds a `reference` field
397
-
398
- ## 0.57.0
399
-
400
- ### Minor Changes
401
-
402
- - ed277e3bd: Remove aws dependency and cache logic from GithubBridge
403
- - d1ed404ba: Add support for auto-generated SDK for type-safe data fetching
404
-
405
- ### Patch Changes
406
-
407
- - 138ceb8c4: Clean up dependencies
408
- - 577d6a5ad: Adds collection arg back for generic queries as optional
409
-
410
- ## 0.56.1
411
-
412
- ### Patch Changes
413
-
414
- - 4b7795612: Adds support for collection.templates to TinaAdmin
415
-
416
- ## 0.56.0
417
-
418
- ### Minor Changes
419
-
420
- - b99baebf1: Add rich-text editor based on mdx, bump React dependency requirement to 16.14
421
-
422
- ### Patch Changes
423
-
424
- - 891623c7c: Adds support for List and Update to TinaAdmin
425
-
426
- ## 0.55.2
427
-
428
- ### Patch Changes
429
-
430
- - 9ecb392ca: Fix bug which would set markdown body to undefined when the payload was emptry"
431
-
432
- ## 0.55.1
433
-
434
- ### Patch Changes
435
-
436
- - ff4446c8e: Adds `getDocumentFields()` query for use with Tina Admin
437
- - 667c33e2a: Add support for rich-text field, update build script to work with unified packages, which are ESM-only
438
-
439
- ## 0.55.0
440
-
441
- ### Minor Changes
442
-
443
- - f3bddeb4a: Added new warning messages for list UI that we do not support by default
444
-
445
- ### Patch Changes
446
-
447
- - 2908f8176: Fixes an issue where nested reference fields weren't updated properly when their values changed.
448
- - 5d83643b2: Adds create document mutations
449
-
450
- ## 0.54.3
451
-
452
- ### Patch Changes
453
-
454
- - 9b27192fe: Build packages with new scripting, which includes preliminary support for ES modules.
455
-
456
- ## 0.54.2
457
-
458
- ### Patch Changes
459
-
460
- - d94fec611: Improve exported types for defineSchema
461
-
462
- ## 0.54.1
463
-
464
- ### Patch Changes
465
-
466
- - 4de977f63: Makes `DateFieldPlugin` timezone-friendly
467
-
468
- ## 0.54.0
469
-
470
- ### Minor Changes
471
-
472
- - 7663e0f7f: Fixed windows issue where you could not save a file
473
-
474
- ## 0.53.0
475
-
476
- ### Minor Changes
477
-
478
- - b4f5e973f: Update datetime field to expect and receive ISO string
479
-
480
- ## 0.52.2
481
-
482
- ### Patch Changes
483
-
484
- - b4bbdda86: Better error messaging when no tina schema files are found
485
-
486
- ## 0.52.1
487
-
488
- ### Patch Changes
489
-
490
- - b05c91c6: Remove console.log
491
-
492
- ## 0.52.0
493
-
494
- ### Minor Changes
495
-
496
- - aa4507697: When working with a new document that queries for a reference, we were not properly building the path information required to update that reference, resulting in an error until the page was refreshed.
497
-
498
- ## 0.51.1
499
-
500
- ### Patch Changes
501
-
502
- - 589c7806: Fix issue where the `isBody` field wasn't properly removing that value from frontmatter. Ensure that the field is not treating any differently for JSON format
503
-
504
- ## 0.51.0
505
-
506
- ### Minor Changes
507
-
508
- - 5a934f6b: Fixed windows path issues
509
-
510
- ### Patch Changes
511
-
512
- - 271a72d7: Use collection label (defined in schema.ts) as form label
513
-
514
- ## 0.50.2
515
-
516
- ### Patch Changes
517
-
518
- - 0970961f: addPendingDocument was expecting params, which are not supported for new doc creation at this time
519
-
520
- ## 0.50.1
521
-
522
- ### Patch Changes
523
-
524
- - 65b3e3a3: Uses checkbox-group field
525
-
526
- ## 0.50.0
527
-
528
- ### Minor Changes
529
-
530
- - 7f3c8c1a: # 🔧 Changes coming to TinaCMS ⚙️
531
-
532
- 👋 You may have noticed we've been hard at-work lately building out a more opinionated approach to TinaCMS. To that end, we've settled around a few key points we'd like to announce. To see the work in progress, check out the [main](https://github.com/tinacms/tinacms/tree/main) branch, which will become the primary branch soon.
533
-
534
- ## Consolidating @tinacms packages in to @tinacms/toolkit
535
-
536
- By nature, Tina relies heavily on React context, and the dependency mismatches from over-modularizing our toolkit has led to many bugs related to missing context. To fix this, we'll be consolidating nearly every package in the @tinacms scope to a single package called `@tinacms/toolkit`
537
-
538
- We'll also be rolling out esm support as it's now much easier to address build improvements
539
-
540
- ## A more focused tinacms package
541
-
542
- The `tinacms` package now comes baked-in with APIs for working with the TinaCMS GraphQL API. Because `@tinacms/toolkit` now encompasses everything you'd need to build your own CMS integration, we're repurposing the `tinacms` package to more accurately reflect the "batteries-included" approach.
543
-
544
- If you haven't been introduced, the GraphQL API is a Git-backed CMS which we'll be leaning into more in the future. With a generous free tier and direct syncing with Github its something we're really excited to push forward. Sign up for free here
545
- Note: tinacms still exports the same APIs, but we'll gradually start moving the backend-agnostic tools to @tinacms/toolkit.
546
-
547
- ## Consolidating the tina-graphql-gateway repo
548
-
549
- The tina-graphql-gateway repo will be absorbed into this one. If you've been working with our GraphQL APIs you'll need to follow our migration guide.
550
-
551
- ## Moving from Lerna to Yarn PNP
552
-
553
- We've had success with Yarn 2 and PNP in other monorepos, if you're a contributor you'll notice some updates to the DX, which should hopefully result in a smoother experience.
554
-
555
- ## FAQ
556
-
557
- ### What about other backends?
558
-
559
- The `@tinacms/toolkit` isn't going anywhere. And if you're using packages like `react-tinacms-strapi` or r`eact-tinacms-github` with success, that won't change much, they'll just be powered by `@tinacms/toolkit` under the hood.
560
-
561
- ### Do I need to do anything?
562
-
563
- We'll be bumping all packages to `0.50.0` to reflect the changes. If you're using @tincams scoped packages those won't receive the upgrade. Unscoped packages like `react-tinacms-editor` will be upgraded, and should be bumped to 0.50.0 as well.
564
- When we move to `1.0.0` we'll be pushing internal APIs to `@tinacms/toolkit`, so that's the long-term location of
565
-
566
- ### Will you continue to patch older versions?
567
-
568
- We'll continue to make security patches, however major bug fixes will likely not see any updates. Keep in mind that `@tinacms/toolkit` will continue to be developed.
569
-
570
- ## 0.2.0
571
-
572
- ### Minor Changes
573
-
574
- - 7351d92f: # Define schema changes
575
-
576
- We're going to be leaning on a more _primitive_ concept of how types are defined with Tina, and in doing so will be introducing some breaking changes to the way schemas are defined. Read the detailed [RFC discussion](https://github.com/tinacms/rfcs/pull/18) for more on this topic, specifically the [latter portions](https://github.com/tinacms/rfcs/pull/18#issuecomment-805400313) of the discussion.
577
-
578
- ## Collections now accept a `fields` _or_ `templates` property
579
-
580
- You can now provide `fields` instead of `templates` for your collection, doing so will result in a more straightforward schema definition:
581
-
582
- ```js
583
- {
584
- collections: [
585
- {
586
- name: 'post',
587
- label: 'Post',
588
- path: 'content/posts',
589
- fields: [
590
- {
591
- name: 'title',
592
- label: 'Title',
593
- type: 'string', // read on below to learn more about _type_ changes
594
- },
595
- ],
596
- // defining `fields` and `templates` would result in a compilation error
597
- },
598
- ]
599
- }
600
- ```
601
-
602
- **Why?**
603
-
604
- Previously, a collection could define multiple templates, the ambiguity introduced with this feature meant that your documents needed a `_template` field on them so we'd know which one they belonged to. It also mean having to disambiguate your queries in graphql:
605
-
606
- ```graphql
607
- getPostDocument(relativePage: $relativePath) {
608
- data {
609
- ...on Article_Doc_Data {
610
- title
611
- }
612
- }
613
- }
614
- ```
615
-
616
- Going forward, if you use `fields` on a collection, you can omit the `_template` key and simplify your query:
617
-
618
- ```graphql
619
- getPostDocument(relativePage: $relativePath) {
620
- data {
621
- title
622
- }
623
- }
624
- ```
625
-
626
- ## `type` changes
627
-
628
- Types will look a little bit different, and are meant to reflect the lowest form of the shape they can represent. Moving forward, the `ui` field will represent the UI portion of what you might expect. For a blog post "description" field, you'd define it like this:
629
-
630
- ```js
631
- {
632
- type: "string",
633
- label: "Description",
634
- name: "description",
635
- }
636
- ```
637
-
638
- By default `string` will use the `text` field, but you can change that by specifying the `component`:
639
-
640
- ```js
641
- {
642
- type: "string",
643
- label: "Description",
644
- name: "description",
645
- ui: {
646
- component: "textarea"
647
- }
648
- }
649
- ```
650
-
651
- For the most part, the UI properties are added to the field and adhere to the existing capabilities of Tina's core [field plugins](https://tina.io/docs/fields/). But there's nothing stopping you from providing your own components -- just be sure to register those with the CMS object on the frontend:
652
-
653
- ```js
654
- {
655
- type: "string",
656
- label: "Description",
657
- name: "description",
658
- ui: {
659
- component: "myMapField"
660
- someAdditionalMapConfig: 'some-value'
661
- }
662
- }
663
- ```
664
-
665
- [Register](https://tina.io/docs/fields/custom-fields/#registering-the-plugin) your `myMapField` with Tina:
666
-
667
- ```js
668
- cms.fields.add({
669
- name: 'myMapField',
670
- Component: MapPicker,
671
- })
672
- ```
673
-
674
- ### One important gotcha
675
-
676
- Every property in the `defineSchema` API must be serlializable. Meaning functions will not work. For example, there's no way to define a `validate` or `parse` function at this level. However, you can either use the [formify](https://tina.io/docs/tina-cloud/client/#formify) API to get access to the Tina form, or provide your own logic by specifying a plugin of your choice:
677
-
678
- ```js
679
- {
680
- type: "string",
681
- label: "Description",
682
- name: "description",
683
- ui: {
684
- component: "myText"
685
- }
686
- }
687
- ```
688
-
689
- And then when you register the plugin, provide your custom logic here:
690
-
691
- ```js
692
- import { TextFieldPlugin } from 'tinacms'
693
-
694
- // ...
695
-
696
- cms.fields.add({
697
- ...TextFieldPlugin, // spread existing text plugin
698
- name: 'myText',
699
- validate: value => {
700
- someValidationLogic(value)
701
- },
702
- })
703
- ```
704
-
705
- **Why?**
706
-
707
- The reality is that under the hood this has made no difference to the backend, so we're removing it as a point of friction. Instead, `type` is the true definition of the field's _shape_, while `ui` can be used for customizing the look and behavior of the field's UI.
708
-
709
- ## Defensive coding in Tina
710
-
711
- When working with GraphQL, there are 2 reasons a property may not be present.
712
-
713
- 1. The data is not a required property. That is to say, if I have a blog post document, and "category" is an optional field, we'll need to make sure we factor that into how we render our page:
714
-
715
- ```tsx
716
- const MyPage = props => {
717
- return (
718
- <>
719
- <h2>{props.getPostDocument.data.title}</h2>
720
- <MyCategoryComponent>
721
- {props.getPostDocument.data?.category}
722
- </MyCategoryComponent>
723
- </>
724
- )
725
- }
726
- ```
727
-
728
- 2. The query did not ask for that field:
729
-
730
- ```graphql
731
- {
732
- getPostDocument {
733
- data {
734
- title
735
- }
736
- }
737
- }
738
- ```
739
-
740
- But with Tina, there's a 3rd scenario: the document may be in an invalid state. Meaning, we could mark the field as `required` _and_ query for the appropriate field, and _still_ not have the expected shape of data. Due to the contextual nature of Tina, it's very common to be in an intermediate state, where your data is incomplete simply because you're still working on it. Most APIs would throw an error when a document is in an invalid state. Or, more likely, you couldn't even request it.
741
-
742
- ## Undefined list fields will return `null`
743
-
744
- Previously an listable field which wasn't defined in the document was treated as an emptry array. So for example:
745
-
746
- ```md
747
- ---
748
- title: 'Hello, World'
749
- categories:
750
- - sports
751
- - movies
752
- ---
753
- ```
754
-
755
- The responsee would be `categories: ['sports', 'movies']`. If you omit the items, but kept the empty array:
756
-
757
- ```md
758
- ---
759
- title: 'Hello, World'
760
- categories: []
761
- ---
762
- ```
763
-
764
- The responsee would be `categories: []`. If you omit the field entirely:
765
-
766
- ```md
767
- ---
768
- title: 'Hello, World'
769
- ---
770
- ```
771
-
772
- The response will be `categories: null`. Previously this would have been `[]`, which was incorrect.
773
-
774
- ## For a listable item which is `required: true` you _must_ provide a `ui.defaultItem` property
775
-
776
- ### Why?
777
-
778
- It's possible for Tina's editing capabilities to introduce an invalid state during edits to list items. Imagine the scenario where you are iterating through an array of objects, and each object has a categories array on it we'd like to render:
779
-
780
- ```tsx
781
- const MyPage = props => {
782
- return props.blocks.map(block => {
783
- return (
784
- <>
785
- <h2>{block.categories.split(',')}</h2>
786
- </>
787
- )
788
- })
789
- }
790
- ```
791
-
792
- For a new item, `categories` will be null, so we'll get an error. This only happens when you're editing your page with Tina, so it's not a production-facing issue.
793
-
794
- ## Every `type` can be a list
795
-
796
- Previously, we had a `list` field, which allowed you to supply a `field` property. Instead, _every_ primitive type can be represented as a list:
797
-
798
- ```js
799
- {
800
- type: "string",
801
- label: "Categories",
802
- name: "categories",
803
- list: true
804
- }
805
- ```
806
-
807
- Additionally, enumerable lists and selects are inferred from the `options` property. The following example is represented by a `select` field:
808
-
809
- ```js
810
- {
811
- type: "string",
812
- label: "Categories",
813
- name: "categories",
814
- options: ["fitness", "movies", "music"]
815
- }
816
- ```
817
-
818
- While this, is a `checkbox` field
819
-
820
- ```js
821
- {
822
- type: "string",
823
- label: "Categories",
824
- name: "categories"
825
- list: true,
826
- options: ["fitness", "movies", "music"]
827
- }
828
- ```
829
-
830
- > Note we may introduce an `enum` type, but haven't discussed it thoroughly
831
-
832
- ## Introducing the `object` type
833
-
834
- Tina currently represents the concept of an _object_ in two ways: a `group` (and `group-list`), which is a uniform collection of fields; and `blocks`, which is a polymporphic collection. Moving forward, we'll be introducing a more comporehensive type, which envelopes the behavior of both `group` and `blocks`, and since _every_ field can be a `list`, this also makes `group-list` redundant.
835
-
836
- > Note: we've previously assumed that `blocks` usage would _always_ be as an array. We'll be keeping that assumption with the `blocks` type for compatibility, but `object` will allow for non-array polymorphic objects.
837
-
838
- ### Defining an `object` type
839
-
840
- An `object` type takes either a `fields` _or_ `templates` property (just like the `collections` definition). If you supply `fields`, you'll end up with what is essentially a `group` item. And if you say `list: true`, you'll have what used to be a `group-list` definition.
841
-
842
- Likewise, if you supply a `templates` field and `list: true`, you'll get the same API as `blocks`. However you can also say `list: false` (or omit it entirely), and you'll have a polymorphic object which is _not_ an array.
843
-
844
- This is identical to the current `blocks` definition:
845
-
846
- ```js
847
- {
848
- type: "object",
849
- label: "Page Sections",
850
- name: "pageSections",
851
- list: true,
852
- templates: [{
853
- label: "Hero",
854
- name: "hero",
855
- fields: [{
856
- label: "Title",
857
- name: "title",
858
- type: "string"
859
- }]
860
- }]
861
- }
862
- ```
863
-
864
- And here is one for `group`:
865
-
866
- ```js
867
- {
868
- type: "object",
869
- label: "Hero",
870
- name: "hero",
871
- fields: [{
872
- label: "Title",
873
- name: "title",
874
- type: "string"
875
- }]
876
- }
877
- ```
878
-
879
- ## `dataJSON` field
880
-
881
- You can now request `dataJSON` for the entire data object as a single query key. This is great for more tedius queries like theme files where including each item in the result is cumbersome.
882
-
883
- > Note there is no typescript help for this feature for now
884
-
885
- ```graphql
886
- getThemeDocument(relativePath: $relativePath) {
887
- dataJSON
888
- }
889
- ```
890
-
891
- ```json
892
- {
893
- "getThemeDocument": {
894
- "dataJSON": {
895
- "every": "field",
896
- "in": {
897
- "the": "document"
898
- },
899
- "is": "returned"
900
- }
901
- }
902
- }
903
- ```
904
-
905
- ## Lists queries will now adhere to the GraphQL connection spec
906
-
907
- [Read the spec](https://relay.dev/graphql/connections.htm)
908
-
909
- Previously, lists would return a simple array of items:
910
-
911
- ```graphql
912
- {
913
- getPostsList {
914
- id
915
- }
916
- }
917
- ```
918
-
919
- Which would result in:
920
-
921
- ```json
922
- {
923
- "data": {
924
- "getPostsList": [
925
- {
926
- "id": "content/posts/voteForPedro.md"
927
- }
928
- ]
929
- }
930
- }
931
- ```
932
-
933
- In the new API, you'll need to step through `edges` & `nodes`:
934
-
935
- ```graphql
936
- {
937
- getPostsList {
938
- edges {
939
- node {
940
- id
941
- }
942
- }
943
- }
944
- }
945
- ```
946
-
947
- ```json
948
- {
949
- "data": {
950
- "getPostsList": {
951
- "edges": [
952
- {
953
- "node": {
954
- "id": "content/posts/voteForPedro.md"
955
- }
956
- }
957
- ]
958
- }
959
- }
960
- }
961
- ```
962
-
963
- **Why?**
964
-
965
- The GraphQL connection spec opens up a more future-proof structure, allowing us to put more information in to the _connection_ itself like how many results have been returned, and how to request the next page of data.
966
-
967
- Read [a detailed explanation](https://graphql.org/learn/pagination/) of how the connection spec provides a richer set of capabilities.
968
-
969
- > Note: sorting and filtering is still not supported for list queries.
970
-
971
- ## `_body` is no longer included by default
972
-
973
- There is instead an `isBody` boolean which can be added to any `string` field
974
-
975
- **Why?**
976
-
977
- Since markdown files sort of have an implicit "body" to them, we were automatically populating a field which represented the body of your markdown file. This wasn't that useful, and kind of annoying. Instead, just attach `isBody` to the field which you want to represent your markdown "body":
978
-
979
- ```js
980
- {
981
- collections: [{
982
- name: "post",
983
- label: "Post",
984
- path: "content/posts",
985
- fields: [
986
- {
987
- name: "title",
988
- label: "Title",
989
- type: "string"
990
- }
991
- {
992
- name: "myBody",
993
- label: "My Body",
994
- type: "string",
995
- component: 'textarea',
996
- isBody: true
997
- }
998
- ]
999
- }]
1000
- }
1001
- ```
1002
-
1003
- This would result in a form field called `My Body` getting saved to the body of your markdown file (if you're using markdown):
1004
-
1005
- ```md
1006
- ---
1007
- title: Hello, World!
1008
- ---
1009
-
1010
- This is the body of the file, it's edited through the "My Body" field in your form.
1011
- ```
1012
-
1013
- ## References now point to more than one collection.
1014
-
1015
- Instead of a `collection` property, you must now define a `collections` field, which is an array:
1016
-
1017
- ```js
1018
- {
1019
- type: "reference",
1020
- label: "Author",
1021
- name: "author",
1022
- collections: ["author"]
1023
- }
1024
- ```
1025
-
1026
- ```graphql
1027
- {
1028
- getPostDocument(relativePath: "hello.md") {
1029
- data {
1030
- title
1031
- author {
1032
- ...on Author_Document {
1033
- name
1034
- }
1035
- ...on Post_Document {
1036
- title
1037
- }
1038
- }
1039
- }
1040
- }
1041
- ```
1042
-
1043
- ## Other breaking changes
1044
-
1045
- ### The `template` field on polymorphic objects (formerly _blocks_) is now `_template`
1046
-
1047
- **Old API:**
1048
-
1049
- ```md
1050
- ---
1051
- ---
1052
- myBlocks:
1053
- - template: hero
1054
- title: Hello
1055
- ---
1056
- ```
1057
-
1058
- **New API:**
1059
-
1060
- ```md
1061
- ---
1062
- ---
1063
- myBlocks:
1064
- - \_template: hero
1065
- title: Hello
1066
- ---
1067
- ```
1068
-
1069
- ### `data` `__typename` values have changed
1070
-
1071
- They now include the proper namespace to prevent naming collisions and no longer require `_Doc_Data` suffix. All generated `__typename` properties are going to be slightly different. We weren't fully namespacing fields so it wasn't possible to guarantee that no collisions would occur. The pain felt here will likely be most seen when querying and filtering through blocks. This ensures the stability of this type in the future
1072
-
1073
- ```graphql
1074
- {
1075
- getPageDocument(relativePath: "home.md") {
1076
- data {
1077
- title
1078
- myBlocks {
1079
- ...on Page_Hero_Data { # previously this would have been Hero_Data
1080
- # ...
1081
- }
1082
- }
1083
- }
1084
- }
1085
- ```
1086
-
1087
- ### Patch Changes
1088
-
1089
- - fdb7724b: Fix stringify for json extensions
1090
- - d42e2bcf: Adds number, datetime, and boolean fields back into primitive field generators
1091
- - 5cd5ce76: - Improve types for ui field
1092
- - Marks system fields as required so the user has a guarantee that they'll be there
1093
- - Return null for listable fields which are null or undefined
1094
- - Handle null values for reference fields better
1095
- - 8c425440: Remmove accidental additional of dataJSON in schema
1096
- - Updated dependencies [7351d92f]
1097
- - tina-graphql-helpers@0.1.2
1098
-
1099
- ## 0.1.25
1100
-
1101
- ### Patch Changes
1102
-
1103
- - 348ef1e5: Testing version bumps go into a PR
1104
-
1105
- ## 0.1.24
1106
-
1107
- ### Patch Changes
1108
-
1109
- - b36de960: lruClearCache should just be clearCache for now
1110
-
1111
- ## 0.1.23
1112
-
1113
- ### Patch Changes
1114
-
1115
- - Bump packages to reflect new changest capabilities
1116
- - Updated dependencies [undefined]
1117
- - tina-graphql-helpers@0.1.1
1118
-
1119
- ## 0.1.22
1120
-
1121
- ### Patch Changes
1122
-
1123
- - Updated dependencies [undefined]
1124
- - tina-graphql-helpers@0.1.0
1125
-
1126
- ## 0.1.21
1127
-
1128
- ### Patch Changes
1129
-
1130
- - Testin
1131
-
1132
- ## 0.1.20
1133
-
1134
- ### Patch Changes
1135
-
1136
- - Testing
1137
-
1138
- ## 0.1.13
1139
-
1140
- ### Patch Changes
1141
-
1142
- - Testing out changesets