Skip to content

Commit 53268a9

Browse files
authored
Merge pull request #485 from constructive-io/update/option-enhancement
Codegen options enchancement and bug fixes
2 parents 6e76a63 + 98baaac commit 53268a9

11 files changed

Lines changed: 4574 additions & 8737 deletions

File tree

graphql/codegen/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,100 @@ Documents options:
8383
Endpoint introspection:
8484
- Set `input.endpoint` and optional `input.headers`
8585
- If your dev server routes by hostname, add `headers: { Host: 'meta8.localhost' }`
86+
87+
## Selection Options
88+
89+
Configure result field selections, mutation input style, and connection pagination shape.
90+
91+
```ts
92+
selection: {
93+
defaultMutationModelFields?: string[]
94+
modelFields?: Record<string, string[]>
95+
mutationInputMode?: 'expanded' | 'model' | 'raw' | 'patchCollapsed'
96+
connectionStyle?: 'nodes' | 'edges'
97+
forceModelOutput?: boolean
98+
}
99+
```
100+
101+
- `defaultMutationModelFields`
102+
- Sets default fields selected from the object payload returned by mutations when the mutation exposes an OBJECT output.
103+
- Example: `['id']` will select only the `id` from the returned model unless overridden per model.
104+
105+
- `modelFields`
106+
- Per‑model overrides for returned object payload fields.
107+
- Example: `{ domain: ['id','domain','subdomain'] }` selects those fields from the `domain` object output.
108+
109+
- `mutationInputMode`
110+
- Controls how mutation variables and `input` are generated.
111+
- `expanded`: one variable per input property; `input` is a flat object of those variables.
112+
- `model`: one variable per property; variables are nested under the singular model key inside `input`.
113+
- `raw`: a single `$input: <CreateXInput>!` variable passed directly as `input: $input`.
114+
- `patchCollapsed`: a single `$patch: <ModelPatch>!` plus required locator(s) (e.g., `$id`), passed as `input: { id: $id, patch: $patch }`.
115+
116+
- `connectionStyle`
117+
- Standardizes connection queries and nested many selections.
118+
- `nodes`: emits `totalCount` and `nodes { ... }`.
119+
- `edges`: emits `totalCount`, `pageInfo { ... }`, and `edges { cursor node { ... } }`.
120+
121+
- `forceModelOutput`
122+
- When `true`, ensures the object payload is selected even if `defaultMutationModelFields` is empty, defaulting to `['id']`.
123+
- Useful to avoid generating mutations that only return `clientMutationId`.
124+
125+
### Examples
126+
127+
Create mutation with raw input:
128+
129+
```graphql
130+
mutation createDomain($input: CreateDomainInput!) {
131+
createDomain(input: $input) {
132+
domain { id, domain, subdomain }
133+
}
134+
}
135+
```
136+
137+
Patch mutation with collapsed patch:
138+
139+
```graphql
140+
mutation updateDomain($id: UUID!, $patch: DomainPatch!) {
141+
updateDomain(input: { id: $id, patch: $patch }) {
142+
domain { id }
143+
clientMutationId
144+
}
145+
}
146+
```
147+
148+
Edges‑style connection query:
149+
150+
```graphql
151+
query getDomainsPaginated($first: Int, $after: Cursor) {
152+
domains(first: $first, after: $after) {
153+
totalCount
154+
pageInfo { hasNextPage hasPreviousPage endCursor startCursor }
155+
edges { cursor node { id domain subdomain } }
156+
}
157+
}
158+
```
159+
160+
## Custom Scalars and Type Overrides
161+
162+
- When your schema exposes custom scalars that are not available in the printed SDL or differ across environments, you can configure both TypeScript scalar typings and GraphQL type names used in generated operations.
163+
164+
- Add these to your config object:
165+
166+
```json
167+
{
168+
"scalars": {
169+
"LaunchqlInternalTypeHostname": "string",
170+
"PgpmInternalTypeHostname": "string"
171+
},
172+
"typeNameOverrides": {
173+
"LaunchqlInternalTypeHostname": "String",
174+
"PgpmInternalTypeHostname": "String"
175+
}
176+
}
177+
```
178+
179+
- `scalars`: maps GraphQL scalar names to TypeScript types for `typescript`/`typescript-operations`/`typescript-graphql-request`/`typescript-react-query` plugins.
180+
- `typeNameOverrides`: rewrites scalar names in generated GraphQL AST so variable definitions and input fields use compatible built‑in GraphQL types.
181+
182+
- These options are also available programmatically through `LaunchQLGenOptions`.

0 commit comments

Comments
 (0)