Skip to content

Commit

Permalink
feat: remove stream and defer directives (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 27, 2024
1 parent 23d6080 commit 1482a89
Show file tree
Hide file tree
Showing 41 changed files with 210 additions and 296 deletions.
3 changes: 3 additions & 0 deletions examples/55_generated/generated_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const year = day * 365.25
const yearsAgo100 = new Date(Date.now() - year * 100).getTime()
const yearsAgo1 = new Date(Date.now() - year).getTime()

// dprint-ignore
const pokemons = await pokemon.query.$batch({
pokemons: [
[`elderPokemons`, {
// ^^^^^^^^^^^^^^^
$: { filter: { birthday: { lte: yearsAgo100 } } },
name: true,
}],
[`babyPokemons`, {
// ^^^^^^^^^^^^^^
$: { filter: { birthday: { gte: yearsAgo1 } } },
name: true,
}],
Expand Down
16 changes: 5 additions & 11 deletions examples/55_generated/generated_directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,26 @@ 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()
// })

// dprint-ignore
const pokemons = await pokemon.query.$batch({
___: {
// $skip: true,
// $defer: true,
$skip: true,
// ^^^^^^^^^^^^
pokemons: {
name: true,
},
},
trainers: {
// $stream: {
// if: true,
// initialCount: 0,
// label: `trainers`,
// },
name: true,
id: {
$skip: true,
// ^^^^^^^^^^^^
},
pokemon: {
id: {
$include: false,
// ^^^^^^^^^^^^^^^^
},
name: true,
},
Expand Down
3 changes: 2 additions & 1 deletion examples/55_generated/generated_document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { showJson } from '../$/helpers.js'
const pokemon = Pokemon.create()

const pokemons = await pokemon.document({
// ^^^^^^^^
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).
Expand Down Expand Up @@ -39,6 +40,6 @@ const pokemons = await pokemon.document({
},
},
})
.run(`pokemonsAndTrainers`)
.run(`pokemonsAndTrainers`) // Set operation name to be executed and send request.

showJson(pokemons)
1 change: 1 addition & 0 deletions examples/55_generated/generated_root-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ 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': '1727398656266'
'x-sent-at-time': '1727402243716'
},
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: 'Fri, 27 Sep 2024 00:57:36 GMT',
date: 'Fri, 27 Sep 2024 01:57:23 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5'
},
Expand Down
14 changes: 0 additions & 14 deletions examples/__outputs__/55_generated/generated_directive.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,5 @@
}
]
}
],
"pokemons": [
{
"name": "Pikachu"
},
{
"name": "Charizard"
},
{
"name": "Squirtle"
},
{
"name": "Bulbasaur"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
parentId: 'edb4fc3f1a36cb35',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: '389e0f006c1b18ee',
traceState: undefined,
name: 'encode',
id: '41893153e418647a',
id: 'bd3e0c33c7f0618a',
kind: 0,
timestamp: 1727398656738000,
duration: 559.083,
timestamp: 1727402244351000,
duration: 815.833,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -33,14 +33,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
parentId: 'edb4fc3f1a36cb35',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: '389e0f006c1b18ee',
traceState: undefined,
name: 'pack',
id: '7f4237b522a4a573',
id: '55ba8c5ec3d2f8a3',
kind: 0,
timestamp: 1727398656741000,
duration: 11605.459,
timestamp: 1727402244355000,
duration: 16379.75,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -57,14 +57,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
parentId: 'edb4fc3f1a36cb35',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: '389e0f006c1b18ee',
traceState: undefined,
name: 'exchange',
id: '10602c9bbc43dd1d',
id: 'bdb99e5752ccec59',
kind: 0,
timestamp: 1727398656753000,
duration: 21156.417,
timestamp: 1727402244373000,
duration: 23841.417,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -81,14 +81,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
parentId: 'edb4fc3f1a36cb35',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: '389e0f006c1b18ee',
traceState: undefined,
name: 'unpack',
id: '2306ef1e07c28f31',
id: 'edf0e40528ece12f',
kind: 0,
timestamp: 1727398656774000,
duration: 1144.458,
timestamp: 1727402244397000,
duration: 1305.875,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -105,14 +105,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
parentId: 'edb4fc3f1a36cb35',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: '389e0f006c1b18ee',
traceState: undefined,
name: 'decode',
id: '7f538ab7279ff6be',
id: '6d4d4750ecff5752',
kind: 0,
timestamp: 1727398656776000,
duration: 189.833,
timestamp: 1727402244398000,
duration: 191.75,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -129,14 +129,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '244b6da7575c00d270d6b60798e72b7e',
traceId: '00f7caa8f793fd361b4dd9d8bfac44a6',
parentId: undefined,
traceState: undefined,
name: 'request',
id: 'edb4fc3f1a36cb35',
id: '389e0f006c1b18ee',
kind: 0,
timestamp: 1727398656738000,
duration: 38270.125,
timestamp: 1727402244349000,
duration: 49758.625,
attributes: {},
status: { code: 0 },
events: [],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"@ark/attest": "^0.19.0",
"@graphql-yoga/plugin-defer-stream": "^3.7.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/sdk-trace-base": "^1.26.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
Expand Down
16 changes: 0 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions src/layers/2_SelectionSet/Directive/$types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Defer } from './_defer.js'
import { Include } from './_include.js'
import { Skip } from './_skip.js'
import { Stream } from './_stream.js'

export interface DirectiveDefinition {
name: string
Expand All @@ -16,17 +14,15 @@ export interface DirectiveLike {
/**
* @see https://spec.graphql.org/draft/#sec-Type-System.Directives.Built-in-Directives
*/
export interface $Fields extends Defer.Field, Stream.Field, Include.Field, Skip.Field {}
export interface $Fields extends Include.Field, Skip.Field {}

export namespace $Groups {
export namespace InlineFragment {
export interface Fields extends Defer.Field, Stream.Field, Include.Field, Skip.Field {}
export interface Fields extends Include.Field, Skip.Field {}
}
}

export const fieldToDef = {
$defer: Defer,
$stream: Stream,
$include: Include,
$skip: Skip,
} satisfies Record<keyof $Fields, DirectiveDefinition>
50 changes: 25 additions & 25 deletions src/layers/2_SelectionSet/print.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,32 @@ describe(`$skip`, () => {
])(...testEachArgs)
})

describe(`$defer`, () => {
test.each([
[s({ object: { $defer: true, id: true } })],
[s({ object: { $defer: false, id: true } })],
[s({ object: { $defer: undefined, id: true } })],
[s({ object: { $defer: { if: true }, id: true } })],
[s({ object: { $defer: { if: false }, id: true } })],
[s({ object: { $defer: { if: undefined }, id: true } })],
[s({ object: { $defer: {}, id: true } })],
[s({ object: { $defer: { label: `foobar` }, id: true } })],
])(...testEachArgs)
})
// describe(`$defer`, () => {
// test.each([
// [s({ object: { $defer: true, id: true } })],
// [s({ object: { $defer: false, id: true } })],
// [s({ object: { $defer: undefined, id: true } })],
// [s({ object: { $defer: { if: true }, id: true } })],
// [s({ object: { $defer: { if: false }, id: true } })],
// [s({ object: { $defer: { if: undefined }, id: true } })],
// [s({ object: { $defer: {}, id: true } })],
// [s({ object: { $defer: { label: `foobar` }, id: true } })],
// ])(...testEachArgs)
// })

describe(`$stream`, () => {
test.each([
[s({ object: { $stream: true, id: true } })],
[s({ object: { $stream: false, id: true } })],
[s({ object: { $stream: undefined, id: true } })],
[s({ object: { $stream: { if: true }, id: true } })],
[s({ object: { $stream: { if: false }, id: true } })],
[s({ object: { $stream: { if: undefined }, id: true } })],
[s({ object: { $stream: {}, id: true } })],
[s({ object: { $stream: { label: `foobar` }, id: true } })],
[s({ object: { $stream: { initialCount: 5 }, id: true } })],
])(...testEachArgs)
})
// describe(`$stream`, () => {
// test.each([
// [s({ object: { $stream: true, id: true } })],
// [s({ object: { $stream: false, id: true } })],
// [s({ object: { $stream: undefined, id: true } })],
// [s({ object: { $stream: { if: true }, id: true } })],
// [s({ object: { $stream: { if: false }, id: true } })],
// [s({ object: { $stream: { if: undefined }, id: true } })],
// [s({ object: { $stream: {}, id: true } })],
// [s({ object: { $stream: { label: `foobar` }, id: true } })],
// [s({ object: { $stream: { initialCount: 5 }, id: true } })],
// ])(...testEachArgs)
// })

describe(`other`, () => {
test.each([
Expand Down
2 changes: 0 additions & 2 deletions src/layers/2_SelectionSet/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ const printDirectives = (fieldValue: FieldValue): string => {
return entriesStrict({
$skip: fieldValue.$skip,
$include: fieldValue.$include,
$defer: fieldValue.$defer,
$stream: fieldValue.$stream,
}).reduce((code, [field, input]) => {
const def = Directive.fieldToDef[field]
code += Directive.Print.toGraphQLDirective(def.create(input))
Expand Down
Loading

0 comments on commit 1482a89

Please sign in to comment.