@fourtwelvelabs/fetch-contentful 0.4.0 → 1.0.0

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/docs/tada.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Typed queries with gql.tada
2
2
 
3
3
  [gql.tada](https://gql-tada.0no.co) infers TypeScript types from your GraphQL
4
- documents *as you write them* — no codegen step in your dev loop, no
4
+ documents _as you write them_ — no codegen step in your dev loop, no
5
5
  hand-written result interfaces that drift from the query. This package ships
6
6
  a companion that points it at a Contentful space: one command writes the
7
7
  schema, the editor plugin config and the `graphql` helper, and
@@ -25,10 +25,10 @@ peer dependencies — they only matter at author time, so they belong in
25
25
  yarn add -D gql.tada @0no-co/graphqlsp
26
26
  ```
27
27
 
28
- **2. Run `tada-init`.** With `CONTENTFUL_SPACE_ID` and
29
- `CONTENTFUL_ACCESS_TOKEN` already in your environment (the same variables the
30
- library reads at runtime — see the README's Configuration section), this
31
- needs no arguments:
28
+ **2. Run `tada-init`.** It reads your credentials from `.env.local`, then
29
+ `.env`, then the shell the same variable names the library uses at runtime
30
+ (see the README's Configuration section). In a typical Next.js project that
31
+ means no arguments at all:
32
32
 
33
33
  ```bash
34
34
  npx @fourtwelvelabs/fetch-contentful tada-init
@@ -46,7 +46,7 @@ It downloads the schema as SDL, adds `@0no-co/graphqlsp` to
46
46
  Add `--dry-run` first if you'd rather see the changes before they happen.
47
47
 
48
48
  That last file is the one you import from as you write queries. It's yours —
49
- commit it, edit it — and it exists because it has to be bound to *your*
49
+ commit it, edit it — and it exists because it has to be bound to _your_
50
50
  space's schema, so it could never ship inside the package:
51
51
 
52
52
  ```ts
@@ -70,7 +70,7 @@ that query's result and variable types by matching it against `introspection`.
70
70
  See [Manual setup](#manual-setup) for writing this file yourself.
71
71
 
72
72
  **3. Restart the TypeScript server** so the editor picks up the plugin. In
73
- VS Code: <kbd>⌘⇧P</kbd> → *TypeScript: Restart TS Server*.
73
+ VS Code: <kbd>⌘⇧P</kbd> → _TypeScript: Restart TS Server_.
74
74
 
75
75
  **4. Write a query**, importing `graphql` from the file step 2 generated.
76
76
  Autocomplete, field validation and types all come from your space's real
@@ -88,7 +88,9 @@ const PageQuery = graphql(`
88
88
  title
89
89
  publishedAt
90
90
  sectionsCollection {
91
- items { heading }
91
+ items {
92
+ heading
93
+ }
92
94
  }
93
95
  }
94
96
  }
@@ -106,7 +108,7 @@ No type arguments, no result interface, no cast.
106
108
 
107
109
  **The result type follows the response you actually receive.** gql.tada types
108
110
  the raw wire shape; `fetchContentful` then applies its own shaping and
109
- unwrapping to *that* type, so `pageCollection.items` arrives as `pages` — an
111
+ unwrapping to _that_ type, so `pageCollection.items` arrives as `pages` — an
110
112
  array — in both the value and the type. `shapeResponseData: false` and
111
113
  `unwrapRootField: false` are reflected too:
112
114
 
@@ -114,7 +116,7 @@ array — in both the value and the type. `shapeResponseData: false` and
114
116
  const raw = await fetchContentful(PageQuery, {
115
117
  variables: { slug: 'home' },
116
118
  shapeResponseData: false,
117
- unwrapRootField: false,
119
+ unwrapRootField: false
118
120
  });
119
121
  // ^? { pageCollection: { items: [...] } | null }
120
122
  ```
@@ -135,14 +137,14 @@ await fetchContentful(PageQuery, { variables: { slgu: 'home' } });
135
137
  **Contentful's custom scalars are typed**, via the `ContentfulScalars` map
136
138
  that `tada-init` wires up. Without it every one of them would be `unknown`:
137
139
 
138
- | Scalar | TypeScript |
139
- | --- | --- |
140
- | `DateTime` | `string` (ISO 8601 at UTC) |
141
- | `Dimension` | `number` (1–4000, image transforms) |
142
- | `HexColor` | `string` (`"rgb:ffffff"`) |
143
- | `JSON` | `JsonValue` (recursive JSON) |
144
- | `Quality` | `number` (1–100) |
145
- | `Circle` | `{ lat, lon, radius }` — a `_within_circle` search area |
140
+ | Scalar | TypeScript |
141
+ | ----------- | ------------------------------------------------------------ |
142
+ | `DateTime` | `string` (ISO 8601 at UTC) |
143
+ | `Dimension` | `number` (1–4000, image transforms) |
144
+ | `HexColor` | `string` (`"rgb:ffffff"`) |
145
+ | `JSON` | `JsonValue` (recursive JSON) |
146
+ | `Quality` | `number` (1–100) |
147
+ | `Circle` | `{ lat, lon, radius }` — a `_within_circle` search area |
146
148
  | `Rectangle` | `{ topLeftLat, topLeftLon, bottomRightLat, bottomRightLon }` |
147
149
 
148
150
  `Circle` and `Rectangle` are geographic search areas used by location
@@ -223,7 +225,7 @@ Contentful can tell you when the content model changes; the schema file can
223
225
  then update itself through a pull request rather than by someone remembering
224
226
  to run a command.
225
227
 
226
- **1. Add a Contentful webhook.** In *SettingsWebhooks*, create one that
228
+ **1. Add a Contentful webhook.** In _SettingsWebhooks_, create one that
227
229
  fires on **ContentType → publish** and **unpublish**, pointing at GitHub's
228
230
  `repository_dispatch` endpoint:
229
231
 
@@ -301,19 +303,20 @@ fetch-contentful tada-refresh [options] Re-download the schema only
301
303
 
302
304
  Both commands accept the same options. Flags win over environment variables.
303
305
 
304
- | Option | Default | Notes |
305
- | --- | --- | --- |
306
- | `--space <id>` | `CONTENTFUL_SPACE_ID` | Required |
307
- | `--environment <id>` | `CONTENTFUL_ENVIRONMENT`, then `master` | |
308
- | `--token <token>` | `CONTENTFUL_ACCESS_TOKEN` | Content Delivery API token |
309
- | `--schema-path <path>` | `./contentful-schema.graphql` | Where the SDL is written |
310
- | `--tada-output <path>` | `./src/contentful-env.d.ts` | Where gql.tada writes its types |
311
- | `--graphql-file <path>` | `./src/graphql.ts` | `tada-init` only |
312
- | `--tsconfig <path>` | `./tsconfig.json` | `tada-init` only |
313
- | `--dry-run` | | Print the changes; write nothing |
314
- | `--force` | | Overwrite an existing graphql file |
315
- | `--cwd <path>` | | Run against another directory |
316
- | `-h`, `--help` | | |
306
+ | Option | Default | Notes |
307
+ | ----------------------- | --------------------------------------- | --------------------------------------- |
308
+ | `--space <id>` | `CONTENTFUL_SPACE_ID` | Required |
309
+ | `--environment <id>` | `CONTENTFUL_ENVIRONMENT`, then `master` | |
310
+ | `--token <token>` | `CONTENTFUL_ACCESS_TOKEN` | Content Delivery API token |
311
+ | `--schema-path <path>` | `./contentful-schema.graphql` | Where the SDL is written |
312
+ | `--tada-output <path>` | `./src/contentful-env.d.ts` | Where gql.tada writes its types |
313
+ | `--graphql-file <path>` | `./src/graphql.ts` | `tada-init` only |
314
+ | `--tsconfig <path>` | `./tsconfig.json` | `tada-init` only |
315
+ | `--dry-run` | | Print the changes; write nothing |
316
+ | `--force` | | Overwrite an existing graphql file |
317
+ | `--cwd <path>` | | Run against another directory |
318
+ | `--env-file <path>` | `.env.local`, then `.env` | Read credentials from this file instead |
319
+ | `-h`, `--help` | | |
317
320
 
318
321
  The `NEXT_PUBLIC_`-prefixed variable names are read as fallbacks, exactly as
319
322
  the library reads them at runtime.
@@ -324,4 +327,26 @@ and formatting, and never overwrites `graphql.ts` unless you pass `--force`.
324
327
  If it cannot patch a tsconfig safely, it changes nothing and prints the block
325
328
  for you to paste in.
326
329
 
330
+ ### Where configuration comes from
331
+
332
+ The commands resolve each setting from the first of these that has a value:
333
+
334
+ 1. a flag — `--space`, `--token`, `--environment`
335
+ 2. the shell environment
336
+ 3. `.env.local`
337
+ 4. `.env`
338
+
339
+ The library itself never reads files from disk — that would break bundlers
340
+ and edge runtimes, and your framework already owns that job. The CLI is a
341
+ different case: it runs from a shell before anything has populated
342
+ `process.env`, and a Next.js project keeps its credentials in `.env.local`,
343
+ which Next only reads when Next itself boots. So the CLI reads that file
344
+ directly, without overwriting anything you have genuinely exported.
345
+
346
+ If your credentials live somewhere else, point at the file:
347
+
348
+ ```bash
349
+ npx @fourtwelvelabs/fetch-contentful tada-refresh --env-file .env.contentful
350
+ ```
351
+
327
352
  The access token is never printed — not in output, not in error messages.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fourtwelvelabs/fetch-contentful",
3
- "version": "0.4.0",
3
+ "version": "1.0.0",
4
4
  "description": "Foolproof, type-safe GraphQL fetching utility for Contentful with automatic query splitting, retries, and response shaping.",
5
5
  "keywords": [
6
6
  "contentful",