@anvilco/types 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @anvilco/types
2
2
 
3
- TypeScript types generated from the [Anvil](https://www.useanvil.com) OpenAPI spec. Consumed internally by `@anvilco/browser` and `@anvilco/react`.
3
+ TypeScript types generated from the [Anvil](https://www.useanvil.com) OpenAPI spec and GraphQL schema. Consumed internally by `@anvilco/browser` and `@anvilco/react`.
4
4
 
5
- Types are regenerated weekly from the production spec via `yarn workspace @anvilco/types generate:rest`.
5
+ The one place for the Anvil SDK's TypeScript types:
6
+
7
+ - **REST**: `paths`, `components` and `operations`, generated from the OpenAPI spec, plus the fill-PDF request types (`FillPdfPayload`, `FillPdfData`, `FillPdfOptions`).
8
+ - **GraphQL**: the `GraphQL` namespace, generated from the schema.
9
+ - **The SDK's own types**: `AnvilOptions`, `GraphQLResponse`, `RESTResponse`, `ResponseError`, `ResponseErrorField`, `RuntimeError` and `Abortable`.
10
+
11
+ ```ts
12
+ import type { GraphQL } from '@anvilco/types'
13
+
14
+ type Packet = GraphQL.Type<'EtchPacket'> // any type in the schema, by name
15
+ type WeldFile = GraphQL.Type<'WeldFile'> // input types too: nullable fields are optional
16
+ type Args = GraphQL.MutationArgs<'createEtchPacket'> // the arguments of any mutation
17
+ type PacketArgs = GraphQL.QueryArgs<'etchPacket'> // …or query
18
+ ```
19
+
20
+ Object types describe the whole object as the schema defines it. A query returns only the fields it selects, so for data you fetched, use the type of your query's result instead.
21
+
22
+ Custom scalars are typed by `GraphQL.Scalars`: `Date` is an ISO 8601 `string`, `JSON` is `unknown`, and `Upload` is `Blob | { data: string; mimetype: string; filename: string } | { url: string; filename?: string }`.
23
+
24
+ ## GraphQL operations
25
+
26
+ To run queries and mutations, use [`@anvilco/core`](../core/README.md). Its `graphql` documents are typed against this schema.
27
+
28
+ The GraphQL schema these types are generated from also ships with the package, at `@anvilco/types/schema.graphql`, for build tooling. Importing `@anvilco/types` never loads it at runtime.
29
+
30
+ ## Regenerating
31
+
32
+ Types are regenerated from production after every Anvil production deploy (`.github/workflows/sync-api-types.yml`), which opens a PR when they change. To regenerate by hand:
33
+
34
+ - REST: `yarn workspace @anvilco/types generate:rest`
35
+ - GraphQL: `ANVIL_API_KEY_PROD_BASE64=... yarn workspace @anvilco/types fetch:schema` refreshes `schema/anvil-schema.graphql` from production, then `yarn workspace @anvilco/types generate:graphql` rebuilds `src/graphql/generated/` from it. The second step needs no network access or key, which is what CI checks.