-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transport-http): support get method (#1066)
- Loading branch information
1 parent
2dbdda3
commit aa935a6
Showing
122 changed files
with
1,807 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createPrefilled } from '../../../../src/entrypoints/client.js' | ||
|
||
import { $defaultSchemaUrl, $Index } from './SchemaRuntime.js' | ||
|
||
export const create = createPrefilled(`Pokemon`, $Index, $defaultSchemaUrl) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Index } from './Index.js' | ||
|
||
declare global { | ||
export namespace GraffleGlobalTypes { | ||
export interface Schemas { | ||
Pokemon: { | ||
name: 'Pokemon' | ||
index: Index | ||
customScalars: {} | ||
featureOptions: { | ||
schemaErrors: true | ||
} | ||
defaultSchemaUrl: null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable */ | ||
|
||
import type * as Schema from './SchemaBuildtime.js' | ||
|
||
export interface Index { | ||
name: 'Pokemon' | ||
Root: { | ||
Query: Schema.Root.Query | ||
Mutation: Schema.Root.Mutation | ||
Subscription: null | ||
} | ||
objects: { | ||
Pokemon: Schema.Object.Pokemon | ||
Trainer: Schema.Object.Trainer | ||
} | ||
unions: {} | ||
interfaces: {} | ||
error: { | ||
objects: {} | ||
objectsTypename: {} | ||
rootResultFields: { | ||
Query: {} | ||
Mutation: {} | ||
Subscription: {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '../../../../src/entrypoints/scalars.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import type * as $ from '../../../../src/entrypoints/schema.js' | ||
import type * as $Scalar from './Scalar.ts' | ||
|
||
// ------------------------------------------------------------ // | ||
// Root // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace Root { | ||
export type Mutation = $.Object$2<'Mutation', { | ||
addPokemon: $.Field< | ||
$.Output.Nullable<Object.Pokemon>, | ||
$.Args<{ | ||
attack: $Scalar.Int | ||
defense: $Scalar.Int | ||
hp: $Scalar.Int | ||
name: $Scalar.String | ||
}> | ||
> | ||
}> | ||
|
||
export type Query = $.Object$2<'Query', { | ||
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null> | ||
pokemonByName: $.Field< | ||
$.Output.Nullable<$.Output.List<Object.Pokemon>>, | ||
$.Args<{ | ||
name: $Scalar.String | ||
}> | ||
> | ||
trainerByName: $.Field< | ||
$.Output.Nullable<Object.Trainer>, | ||
$.Args<{ | ||
name: $Scalar.String | ||
}> | ||
> | ||
trainers: $.Field<$.Output.Nullable<$.Output.List<Object.Trainer>>, null> | ||
}> | ||
} | ||
|
||
// ------------------------------------------------------------ // | ||
// Enum // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace Enum { | ||
// -- no types -- | ||
} | ||
|
||
// ------------------------------------------------------------ // | ||
// InputObject // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace InputObject { | ||
// -- no types -- | ||
} | ||
|
||
// ------------------------------------------------------------ // | ||
// Interface // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace Interface { | ||
// -- no types -- | ||
} | ||
|
||
// ------------------------------------------------------------ // | ||
// Object // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace Object { | ||
export type Pokemon = $.Object$2<'Pokemon', { | ||
attack: $.Field<$.Output.Nullable<$Scalar.Int>, null> | ||
defense: $.Field<$.Output.Nullable<$Scalar.Int>, null> | ||
hp: $.Field<$.Output.Nullable<$Scalar.Int>, null> | ||
id: $.Field<$.Output.Nullable<$Scalar.Int>, null> | ||
name: $.Field<$.Output.Nullable<$Scalar.String>, null> | ||
trainer: $.Field<$.Output.Nullable<Object.Trainer>, null> | ||
}> | ||
|
||
export type Trainer = $.Object$2<'Trainer', { | ||
id: $.Field<$.Output.Nullable<$Scalar.Int>, null> | ||
name: $.Field<$.Output.Nullable<$Scalar.String>, null> | ||
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null> | ||
}> | ||
} | ||
|
||
// ------------------------------------------------------------ // | ||
// Union // | ||
// ------------------------------------------------------------ // | ||
|
||
export namespace Union { | ||
// -- no types -- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* eslint-disable */ | ||
|
||
import * as $ from '../../../../src/entrypoints/schema.js' | ||
import * as $Scalar from './Scalar.js' | ||
|
||
export const $defaultSchemaUrl = undefined | ||
|
||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
export const Pokemon = $.Object$(`Pokemon`, { | ||
attack: $.field($.Output.Nullable($Scalar.Int)), | ||
defense: $.field($.Output.Nullable($Scalar.Int)), | ||
hp: $.field($.Output.Nullable($Scalar.Int)), | ||
id: $.field($.Output.Nullable($Scalar.Int)), | ||
name: $.field($.Output.Nullable($Scalar.String)), | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
trainer: $.field($.Output.Nullable(() => Trainer)), | ||
}) | ||
|
||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
export const Trainer = $.Object$(`Trainer`, { | ||
id: $.field($.Output.Nullable($Scalar.Int)), | ||
name: $.field($.Output.Nullable($Scalar.String)), | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))), | ||
}) | ||
|
||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
export const Mutation = $.Object$(`Mutation`, { | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
addPokemon: $.field( | ||
$.Output.Nullable(() => Pokemon), | ||
$.Args({ attack: $Scalar.Int, defense: $Scalar.Int, hp: $Scalar.Int, name: $Scalar.String }), | ||
), | ||
}) | ||
|
||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
export const Query = $.Object$(`Query`, { | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))), | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
pokemonByName: $.field($.Output.Nullable($.Output.List(() => Pokemon)), $.Args({ name: $Scalar.String })), | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
trainerByName: $.field($.Output.Nullable(() => Trainer), $.Args({ name: $Scalar.String })), | ||
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. | ||
trainers: $.field($.Output.Nullable($.Output.List(() => Trainer))), | ||
}) | ||
|
||
export const $Index = { | ||
name: 'Pokemon' as const, | ||
Root: { | ||
Query, | ||
Mutation, | ||
Subscription: null, | ||
}, | ||
objects: { | ||
Pokemon, | ||
Trainer, | ||
}, | ||
unions: {}, | ||
interfaces: {}, | ||
error: { | ||
objects: {}, | ||
objectsTypename: {}, | ||
rootResultFields: { | ||
Query: {}, | ||
Mutation: {}, | ||
Subscription: {}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { ResultSet, SelectionSet } from '../../../../src/entrypoints/schema.js' | ||
import type { Index } from './Index.js' | ||
|
||
// Runtime | ||
// ------- | ||
|
||
import { createSelect } from '../../../../src/entrypoints/client.js' | ||
export const Select = createSelect(`default`) | ||
|
||
// Buildtime | ||
// --------- | ||
|
||
export namespace Select { | ||
// Root Types | ||
// ---------- | ||
|
||
export type Mutation<$SelectionSet extends SelectionSet.Root<Index, 'Mutation'>> = ResultSet.Root< | ||
$SelectionSet, | ||
Index, | ||
'Mutation' | ||
> | ||
|
||
export type Query<$SelectionSet extends SelectionSet.Root<Index, 'Query'>> = ResultSet.Root< | ||
$SelectionSet, | ||
Index, | ||
'Query' | ||
> | ||
|
||
// Object Types | ||
// ------------ | ||
|
||
export type Pokemon<$SelectionSet extends SelectionSet.Object<Index['objects']['Pokemon'], Index>> = | ||
ResultSet.Object$<$SelectionSet, Index['objects']['Pokemon'], Index> | ||
|
||
export type Trainer<$SelectionSet extends SelectionSet.Object<Index['objects']['Trainer'], Index>> = | ||
ResultSet.Object$<$SelectionSet, Index['objects']['Trainer'], Index> | ||
|
||
// Union Types | ||
// ----------- | ||
|
||
// -- None -- | ||
|
||
// Interface Types | ||
// --------------- | ||
|
||
// -- None -- | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as Pokemon from './_.js' |
2 changes: 1 addition & 1 deletion
2
...generated-clients/SocialStudies/Client.ts → ...generated-clients/SocialStudies/Client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
type Include<T, U> = Exclude<T, Exclude<T, U>> | ||
|
||
type ObjectWithTypeName = { __typename: string } | ||
|
||
const ErrorObjectsTypeNameSelectedEnum = {} as Record<string, ObjectWithTypeName> | ||
|
||
const ErrorObjectsTypeNameSelected = Object.values(ErrorObjectsTypeNameSelectedEnum) | ||
|
||
type ErrorObjectsTypeNameSelected = (typeof ErrorObjectsTypeNameSelected)[number] | ||
|
||
export const isError = <$Value>(value: $Value): value is Include<$Value, ErrorObjectsTypeNameSelected> => { | ||
return typeof value === `object` && value !== null && `__typename` in value | ||
&& ErrorObjectsTypeNameSelected.some(_ => _.__typename === value.__typename) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '../../../../src/entrypoints/scalars.js' |
2 changes: 1 addition & 1 deletion
2
...-clients/SocialStudies/SchemaBuildtime.ts → ...-clients/SocialStudies/SchemaBuildtime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ed-clients/SocialStudies/SchemaRuntime.ts → ...ed-clients/SocialStudies/SchemaRuntime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...generated-clients/SocialStudies/Select.ts → ...generated-clients/SocialStudies/Select.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { create } from './Client.js' | ||
export { isError } from './Error.js' | ||
export { Select } from './Select.js' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import getPort from 'get-port' | ||
import type { GraphQLSchema } from 'graphql' | ||
import { createYoga } from 'graphql-yoga' | ||
import { createServer } from 'node:http' | ||
import { inspect } from 'node:util' | ||
|
||
export const publicGraphQLSchemaEndpoints = { | ||
SocialStudies: `https://countries.trevorblades.com/graphql`, | ||
} | ||
|
||
export const showPartition = `---------------------------------------- SHOW ----------------------------------------` | ||
|
||
export const show = (value: unknown) => { | ||
console.log(showPartition) | ||
console.log(inspect(value, { depth: null, colors: true })) | ||
} | ||
|
||
export const showJson = (value: unknown) => { | ||
console.log(showPartition) | ||
console.log(JSON.stringify(value, null, 2)) | ||
} | ||
|
||
export const serveSchema = async (input: { schema: GraphQLSchema }) => { | ||
const { schema } = input | ||
const yoga = createYoga({ schema }) | ||
const server = createServer(yoga) // eslint-disable-line | ||
const port = await getPort({ port: [3000, 3001, 3002, 3003, 3004] }) | ||
const url = new URL(`http://localhost:${String(port)}/graphql`) | ||
server.listen(port) | ||
await new Promise((resolve) => | ||
server.once(`listening`, () => { | ||
resolve(undefined) | ||
}) | ||
) | ||
const stop = async () => { | ||
await new Promise((resolve) => { | ||
server.close(resolve) | ||
setImmediate(() => { | ||
server.emit(`close`) | ||
}) | ||
}) | ||
} | ||
|
||
return { | ||
yoga, | ||
server, | ||
port, | ||
url, | ||
stop, | ||
} | ||
} | ||
|
||
export type SchemaServer = Awaited<ReturnType<typeof serveSchema>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { printSchema } from 'graphql' | ||
import { writeFileSync } from 'node:fs' | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { schema } from './schema.js' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = dirname(__filename) | ||
|
||
const sdl = printSchema(schema) | ||
const path = join(__dirname, `./schema.graphql`) | ||
writeFileSync(path, sdl) | ||
|
||
console.log(`GraphQL SDL has been written to ${path}`) |
Oops, something went wrong.