Skip to content

Commit

Permalink
refactor: SelectionSet (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 24, 2024
1 parent 5c62024 commit d87460f
Show file tree
Hide file tree
Showing 40 changed files with 699 additions and 661 deletions.
112 changes: 62 additions & 50 deletions examples/$/generated-clients/atlas/modules/SelectionSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export interface Query {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |
Expand Down Expand Up @@ -238,21 +240,23 @@ export interface Continent extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Continent {
export type code$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type code$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type code = $SelectionSet.NoArgsIndicator
export type code = $SelectionSet.Indicator.NoArgsIndicator

export interface countries extends _RefDefs._Country {}
export type countries$Expanded = countries
export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator
}

//
Expand Down Expand Up @@ -346,41 +350,43 @@ export interface Country extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Country {
export type awsRegion$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type awsRegion$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type awsRegion = $SelectionSet.NoArgsIndicator
export type awsRegion = $SelectionSet.Indicator.NoArgsIndicator

export type capital$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type capital$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type capital = $SelectionSet.NoArgsIndicator
export type capital = $SelectionSet.Indicator.NoArgsIndicator

export type code$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type code$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type code = $SelectionSet.NoArgsIndicator
export type code = $SelectionSet.Indicator.NoArgsIndicator

export interface continent extends _RefDefs._Continent {}
export type continent$Expanded = continent
export type currencies$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type currencies$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type currencies = $SelectionSet.NoArgsIndicator
export type currencies = $SelectionSet.Indicator.NoArgsIndicator

export type currency$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type currency$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type currency = $SelectionSet.NoArgsIndicator
export type currency = $SelectionSet.Indicator.NoArgsIndicator

export type emoji$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type emoji$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type emoji = $SelectionSet.NoArgsIndicator
export type emoji = $SelectionSet.Indicator.NoArgsIndicator

export type emojiU$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type emojiU$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type emojiU = $SelectionSet.NoArgsIndicator
export type emojiU = $SelectionSet.Indicator.NoArgsIndicator

export interface languages extends _RefDefs._Language {}
export type languages$Expanded = languages
Expand All @@ -397,21 +403,21 @@ export namespace Country {
}
>

export type name$Expanded = $Utilities.UnionExpanded<$SelectionSet.ClientIndicator | name$SelectionSet>
export type name$Expanded = $Utilities.UnionExpanded<$SelectionSet.Indicator.ClientIndicator | name$SelectionSet>

export type name = $SelectionSet.ClientIndicator | name$SelectionSet
export type name = $SelectionSet.Indicator.ClientIndicator | name$SelectionSet

export type native$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type native$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type native = $SelectionSet.NoArgsIndicator
export type native = $SelectionSet.Indicator.NoArgsIndicator

export type phone$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type phone$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type phone = $SelectionSet.NoArgsIndicator
export type phone = $SelectionSet.Indicator.NoArgsIndicator

export type phones$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type phones$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type phones = $SelectionSet.NoArgsIndicator
export type phones = $SelectionSet.Indicator.NoArgsIndicator

export interface states extends _RefDefs._State {}
export type states$Expanded = states
Expand Down Expand Up @@ -466,27 +472,29 @@ export interface Language extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Language {
export type code$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type code$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type code = $SelectionSet.NoArgsIndicator
export type code = $SelectionSet.Indicator.NoArgsIndicator

export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator

export type native$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type native$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type native = $SelectionSet.NoArgsIndicator
export type native = $SelectionSet.Indicator.NoArgsIndicator

export type rtl$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type rtl$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type rtl = $SelectionSet.NoArgsIndicator
export type rtl = $SelectionSet.Indicator.NoArgsIndicator
}

//
Expand Down Expand Up @@ -532,21 +540,23 @@ export interface State extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace State {
export type code$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type code$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type code = $SelectionSet.NoArgsIndicator
export type code = $SelectionSet.Indicator.NoArgsIndicator

export interface country extends _RefDefs._Country {}
export type country$Expanded = country
export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator
}

//
Expand Down Expand Up @@ -592,23 +602,25 @@ export interface Subdivision extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Subdivision {
export type code$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type code$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type code = $SelectionSet.NoArgsIndicator
export type code = $SelectionSet.Indicator.NoArgsIndicator

export type emoji$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type emoji$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type emoji = $SelectionSet.NoArgsIndicator
export type emoji = $SelectionSet.Indicator.NoArgsIndicator

export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator
}

/**
Expand Down
44 changes: 26 additions & 18 deletions examples/$/generated-clients/pokemon/modules/SelectionSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export interface Mutation {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |
Expand Down Expand Up @@ -120,7 +122,9 @@ export interface Query {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |
Expand Down Expand Up @@ -223,31 +227,33 @@ export interface Pokemon extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Pokemon {
export type attack$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type attack$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type attack = $SelectionSet.NoArgsIndicator
export type attack = $SelectionSet.Indicator.NoArgsIndicator

export type defense$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type defense$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type defense = $SelectionSet.NoArgsIndicator
export type defense = $SelectionSet.Indicator.NoArgsIndicator

export type hp$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type hp$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type hp = $SelectionSet.NoArgsIndicator
export type hp = $SelectionSet.Indicator.NoArgsIndicator

export type id$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type id$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type id = $SelectionSet.NoArgsIndicator
export type id = $SelectionSet.Indicator.NoArgsIndicator

export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator

export interface trainer extends _RefDefs._Trainer {}
export type trainer$Expanded = trainer
Expand Down Expand Up @@ -296,19 +302,21 @@ export interface Trainer extends $SelectionSet.Bases.ObjectLike {
*
* @see https://graphql.org/learn/queries/#meta-fields
*/
__typename?: $SelectionSet.NoArgsIndicator$Expanded | $SelectionSet.AliasInput<$SelectionSet.NoArgsIndicator>
__typename?:
| $SelectionSet.Indicator.NoArgsIndicator$Expanded
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

// ----------------------------------------| Fields Interfaces |

export namespace Trainer {
export type id$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type id$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type id = $SelectionSet.NoArgsIndicator
export type id = $SelectionSet.Indicator.NoArgsIndicator

export type name$Expanded = $SelectionSet.NoArgsIndicator$Expanded
export type name$Expanded = $SelectionSet.Indicator.NoArgsIndicator$Expanded

export type name = $SelectionSet.NoArgsIndicator
export type name = $SelectionSet.Indicator.NoArgsIndicator

export interface pokemon extends _RefDefs._Pokemon {}
export type pokemon$Expanded = pokemon
Expand Down
10 changes: 5 additions & 5 deletions src/layers/2_generator/code/SelectionSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ const renderField = createCodeGenerator<{ field: GraphQLField<any, any> }>(
code.push(
Helpers.type(
`${nameRendered}$Expanded`,
`$Utilities.UnionExpanded<$SelectionSet.ClientIndicator | ${nameRendered}$SelectionSet>`,
`$Utilities.UnionExpanded<$SelectionSet.Indicator.ClientIndicator | ${nameRendered}$SelectionSet>`,
),
)
code.push(``)
code.push(
Helpers.type(nameRendered, `$SelectionSet.ClientIndicator | ${nameRendered}$SelectionSet`),
Helpers.type(nameRendered, `$SelectionSet.Indicator.ClientIndicator | ${nameRendered}$SelectionSet`),
)
code.push(``)
} else {
Expand All @@ -290,9 +290,9 @@ const renderField = createCodeGenerator<{ field: GraphQLField<any, any> }>(
code.push(``)
}
} else {
code.push(Helpers.type(`${nameRendered}$Expanded`, `$SelectionSet.NoArgsIndicator$Expanded`))
code.push(Helpers.type(`${nameRendered}$Expanded`, `$SelectionSet.Indicator.NoArgsIndicator$Expanded`))
code.push(``)
code.push(Helpers.type(nameRendered, `$SelectionSet.NoArgsIndicator`))
code.push(Helpers.type(nameRendered, `$SelectionSet.Indicator.NoArgsIndicator`))
code.push(``)
}
} else {
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace Helpers {
export const __typename = (kind: 'union' | 'interface' | 'object') => {
return `
${__typenameDoc(kind)}
${outputFieldAlisable(`__typename`, `$SelectionSet.NoArgsIndicator`)}
${outputFieldAlisable(`__typename`, `$SelectionSet.Indicator.NoArgsIndicator`)}
`
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export interface DirectiveLike {
name: string
args: Record<string, any>
}
import type { DirectiveLike } from './$types.js'

export const toGraphQLDirective = (directive: DirectiveLike) => {
return `@${directive.name}(${toGraphQLDirectiveArgs(directive.args)})`
}

export const toGraphQLDirectiveArgs = (args: object) => {
export const toGraphQLDirectiveArgs = (args: DirectiveLike['args']) => {
return Object.entries(args).filter(([_, v]) => v !== undefined).map(([k, clientValue]) => {
// todo can directives receive custom scalars?
const value = JSON.stringify(clientValue)
Expand Down
Loading

0 comments on commit d87460f

Please sign in to comment.