Skip to content

Commit

Permalink
fix: field groups (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 27, 2024
1 parent 06d3990 commit 23d6080
Show file tree
Hide file tree
Showing 67 changed files with 1,474 additions and 351 deletions.
24 changes: 16 additions & 8 deletions examples/$/generated-clients/pokemon/modules/SelectionSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export interface Mutation {
* Inline fragments for field groups.
*
* Generally a niche feature. This can be useful for example to apply an `@include` directive to a subset of the
* selection set allowing a variable to opt-in or not to that part of the selection.
* selection set in turn allowing you to pass a variable to opt in/out of that selection during execution on the server.
*
* @see https://spec.graphql.org/draft/#sec-Inline-Fragments
*/
___?: Mutation | Mutation[]
___?: Mutation$FragmentInline | Mutation$FragmentInline[]

/**
* A meta field. Is the name of the type being selected.
Expand All @@ -57,6 +57,8 @@ export interface Mutation {
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

export interface Mutation$FragmentInline extends Mutation, $SelectionSet.Directive.$Groups.InlineFragment.Fields {}

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

export namespace Mutation {
Expand Down Expand Up @@ -115,11 +117,11 @@ export interface Query {
* Inline fragments for field groups.
*
* Generally a niche feature. This can be useful for example to apply an `@include` directive to a subset of the
* selection set allowing a variable to opt-in or not to that part of the selection.
* selection set in turn allowing you to pass a variable to opt in/out of that selection during execution on the server.
*
* @see https://spec.graphql.org/draft/#sec-Inline-Fragments
*/
___?: Query | Query[]
___?: Query$FragmentInline | Query$FragmentInline[]

/**
* A meta field. Is the name of the type being selected.
Expand All @@ -131,6 +133,8 @@ export interface Query {
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

export interface Query$FragmentInline extends Query, $SelectionSet.Directive.$Groups.InlineFragment.Fields {}

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

export namespace Query {
Expand Down Expand Up @@ -265,11 +269,11 @@ export interface Pokemon extends $SelectionSet.Bases.ObjectLike {
* Inline fragments for field groups.
*
* Generally a niche feature. This can be useful for example to apply an `@include` directive to a subset of the
* selection set allowing a variable to opt-in or not to that part of the selection.
* selection set in turn allowing you to pass a variable to opt in/out of that selection during execution on the server.
*
* @see https://spec.graphql.org/draft/#sec-Inline-Fragments
*/
___?: Pokemon | Pokemon[]
___?: Pokemon$FragmentInline | Pokemon$FragmentInline[]

/**
* A meta field. Is the name of the type being selected.
Expand All @@ -281,6 +285,8 @@ export interface Pokemon extends $SelectionSet.Bases.ObjectLike {
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

export interface Pokemon$FragmentInline extends Pokemon, $SelectionSet.Directive.$Groups.InlineFragment.Fields {}

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

export namespace Pokemon {
Expand Down Expand Up @@ -344,11 +350,11 @@ export interface Trainer extends $SelectionSet.Bases.ObjectLike {
* Inline fragments for field groups.
*
* Generally a niche feature. This can be useful for example to apply an `@include` directive to a subset of the
* selection set allowing a variable to opt-in or not to that part of the selection.
* selection set in turn allowing you to pass a variable to opt in/out of that selection during execution on the server.
*
* @see https://spec.graphql.org/draft/#sec-Inline-Fragments
*/
___?: Trainer | Trainer[]
___?: Trainer$FragmentInline | Trainer$FragmentInline[]

/**
* A meta field. Is the name of the type being selected.
Expand All @@ -360,6 +366,8 @@ export interface Trainer extends $SelectionSet.Bases.ObjectLike {
| $SelectionSet.AliasInput<$SelectionSet.Indicator.NoArgsIndicator>
}

export interface Trainer$FragmentInline extends Trainer, $SelectionSet.Directive.$Groups.InlineFragment.Fields {}

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

export namespace Trainer {
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions examples/55_generated/generated_batch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* This example shows how to write batches of GraphQL root fields (aka. entrypoints) in the TypeScript interface.
*/

import { Pokemon } from '../$/generated-clients/pokemon/__.js'
import { showJson } from '../$/helpers.js'

const pokemon = Pokemon.create()

// dprint-ignore
const pokemons = await pokemon.query.$batch({
// ^^^^^^
pokemonByName: {
//^^^^^^^^^^^^^
$: { name: `Pikachu` },
name: true,
id: true,
},
trainerByName: {
//^^^^^^^^^^^^^
$: { name: `Ash` },
name: true,
id: true,
},
})

showJson(pokemons)
42 changes: 42 additions & 0 deletions examples/55_generated/generated_directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* This example shows how to use special fields to write GraphQL document directives.
*/

// import { parse, print } from 'graphql'
import { Pokemon } from '../$/generated-clients/pokemon/__.js'
import { showJson } from '../$/helpers.js'

const pokemon = Pokemon.create()
// .anyware(({ pack }) => {
// console.log(print(parse(pack.input.query)))
// return pack()
// })

const pokemons = await pokemon.query.$batch({
___: {
// $skip: true,
// $defer: true,
pokemons: {
name: true,
},
},
trainers: {
// $stream: {
// if: true,
// initialCount: 0,
// label: `trainers`,
// },
name: true,
id: {
$skip: true,
},
pokemon: {
id: {
$include: false,
},
name: true,
},
},
})

showJson(pokemons)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { showJson } from '../$/helpers.js'
const pokemon = Pokemon.create()

const pokemons = await pokemon.document({
query: { // A root type.
pokemonsAndTrainers: { // A name of an the operation.
trainers: { // A root field.
name: true, // A field.
query: { // An operation type.
pokemonsAndTrainers: { // A name chosen by you for this operation.
trainers: { // A selection on a Query type field (aka. root field, entrypoint).
name: true, // A selection on a scalar type field
},
pokemons: {
$: { // A field's arguments
Expand All @@ -27,18 +27,18 @@ const pokemons = await pokemon.document({
mutation: {
makeSomeNewPokemons: {
addPokemon: [
['addAngryPikachu', {
[`addAngryPikachu`, {
$: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100 },
name: true,
}],
['addAngryCharizard', {
[`addAngryCharizard`, {
$: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100 },
name: true,
}],
],
},
},
})
.run('pokemonsAndTrainers')
.run(`pokemonsAndTrainers`)

showJson(pokemons)
12 changes: 12 additions & 0 deletions examples/55_generated/generated_root-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This example shows how to use dedicated root field methods to easily operate on one GraphQL root field at at time. If you need to work with multiple root fields, check out the `batch` example.
*/

import { Pokemon } from '../$/generated-clients/pokemon/__.js'
import { showJson } from '../$/helpers.js'

const pokemon = Pokemon.create()

const pokemons = await pokemon.query.pokemons({ name: true })

showJson(pokemons)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
headers: Headers {
accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
'content-type': 'application/json',
'x-sent-at-time': '1727369127674'
'x-sent-at-time': '1727398656266'
},
signal: undefined,
method: 'post',
Expand Down
2 changes: 1 addition & 1 deletion examples/__outputs__/20_output/output_envelope.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
headers: Headers {
'content-type': 'application/graphql-response+json; charset=utf-8',
'content-length': '104',
date: 'Thu, 26 Sep 2024 16:45:27 GMT',
date: 'Fri, 27 Sep 2024 00:57:36 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5'
},
Expand Down
13 changes: 13 additions & 0 deletions examples/__outputs__/55_generated/generated_batch.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---------------------------------------- SHOW ----------------------------------------
{
"pokemonByName": [
{
"name": "Pikachu",
"id": 1
}
],
"trainerByName": {
"name": "Ash",
"id": 1
}
}
38 changes: 38 additions & 0 deletions examples/__outputs__/55_generated/generated_directive.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---------------------------------------- SHOW ----------------------------------------
{
"trainers": [
{
"name": "Ash",
"pokemon": [
{
"name": "Pikachu"
},
{
"name": "Charizard"
}
]
},
{
"name": "Misty",
"pokemon": [
{
"name": "Squirtle"
}
]
}
],
"pokemons": [
{
"name": "Pikachu"
},
{
"name": "Charizard"
},
{
"name": "Squirtle"
},
{
"name": "Bulbasaur"
}
]
}
15 changes: 15 additions & 0 deletions examples/__outputs__/55_generated/generated_root-field.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---------------------------------------- SHOW ----------------------------------------
[
{
"name": "Pikachu"
},
{
"name": "Charizard"
},
{
"name": "Squirtle"
},
{
"name": "Bulbasaur"
}
]
Loading

0 comments on commit 23d6080

Please sign in to comment.