Skip to content

Commit

Permalink
chore: refactor examples directories system (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 14, 2024
1 parent aec075d commit 060db41
Show file tree
Hide file tree
Showing 227 changed files with 576 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to cancel requests using an `AbortController` signal.
*/

import { Graffle } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const abortController = new AbortController()
// ^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

/* eslint-disable */
import { Graffle } from '../src/entrypoints/main.js'
import { showJson } from './$/helpers.js'
import { publicGraphQLSchemaEndpoints } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { showJson } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Atlas })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to leverage the extension system to dynamically manipulate headers per request.
*/

import { Graffle } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle
.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This example shows how to use the `transport` configuration to control request headers. Notice how empty string headers unset previously set headers.
*/

import { Graffle } from '../src/entrypoints/main.js'
import { show } from './$/helpers.js'
import { publicGraphQLSchemaEndpoints } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { show } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* to be sent over HTTP GET method. Note write-kind operations (mutation) are still sent over HTTP POST method.
*/

import { Pokemon } from './$/generated-clients/pokemon/__.js'
import { serveSchema, show } from './$/helpers.js'
import { schema } from './$/schemas/pokemon/schema.js'
import { Pokemon } from '../$/generated-clients/pokemon/__.js'
import { serveSchema, show } from '../$/helpers.js'
import { schema } from '../$/schemas/pokemon/schema.js'

const server = await serveSchema({ schema })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This example shows how to use the `raw` configuration of transport configuration to easily access low-level `RequestInit` configuration.
*/

import { Graffle } from '../src/entrypoints/main.js'
import { show } from './$/helpers.js'
import { publicGraphQLSchemaEndpoints } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { show } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows the default output behavior.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { show } from './$/helpers.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { show } from '../$/helpers.js'

const atlas = Atlas.create()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to configure output to use the envelope.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { show } from './$/helpers.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { show } from '../$/helpers.js'

const atlas = Atlas.create({
output: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to configure output to embed errors into the envelope.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { show } from './$/helpers.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { show } from '../$/helpers.js'

// dprint-ignore
const atlas = Atlas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This example shows how to configure output to throw errors even when using the envelope.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'

// dprint-ignore
const atlas = Atlas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to configure output to have errors returned instead of e.g. thrown.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { show } from './$/helpers.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { show } from '../$/helpers.js'

// dprint-ignore
const atlas = Atlas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This example shows how to configure output to have only certain kinds of errors returned while others thrown.
*/

import { Pokemon } from './$/generated-clients/pokemon/__.js'
import { serveSchema, show } from './$/helpers.js'
import { schema } from './$/schemas/pokemon/schema.js'
import { Pokemon } from '../$/generated-clients/pokemon/__.js'
import { serveSchema, show } from '../$/helpers.js'
import { schema } from '../$/schemas/pokemon/schema.js'

const server = await serveSchema({ schema: schema })

Expand Down
6 changes: 3 additions & 3 deletions examples/raw|raw.ts → examples/30_raw/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This example shows how to send a request using a Document instance for the GraphQL document.
*/

import { Opentelemetry, OrThrow } from '../src/entrypoints/extensions.js'
import { gql, Graffle } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { Opentelemetry, OrThrow } from '../../src/entrypoints/extensions.js'
import { gql, Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Atlas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to send a request using a string for the GraphQL document.
*/

import { Graffle } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Atlas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* of automation would generate the types for you.
*/

import { Graffle, type TypedDocumentString } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { Graffle, type TypedDocumentString } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Atlas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import type { TypedQueryDocumentNode } from 'graphql'
import { gql, Graffle } from '../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js'
import { gql, Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Atlas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql'
import { Graffle } from '../src/entrypoints/main.js'
import { showJson } from './$/helpers.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { showJson } from '../$/helpers.js'

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This example shows how to use the TypeScript interface for GraphQL arguments.
*/

import { Atlas } from './$/generated-clients/atlas/__.js'
import { showJson } from './$/helpers.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { showJson } from '../$/helpers.js'

const atlas = Atlas.create()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
import { Opentelemetry } from '../src/entrypoints/extensions.js'
import { Atlas } from './$/generated-clients/atlas/__.js'
import { interceptAndShowOutput, show } from './$/helpers.js'
import { Opentelemetry } from '../../src/entrypoints/extensions.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { interceptAndShowOutput, show } from '../$/helpers.js'

interceptAndShowOutput()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* This example shows how to use the Or Throw extension to throw errors for one-off cases.
*/

import { OrThrow } from '../src/entrypoints/extensions.js'
import { Atlas } from './$/generated-clients/atlas/__.js'
import { interceptAndShowUncaughtErrors, show } from './$/show.js'
import { OrThrow } from '../../src/entrypoints/extensions.js'
import { Atlas } from '../$/generated-clients/atlas/__.js'
import { interceptAndShowUncaughtErrors, show } from '../$/show.js'

interceptAndShowUncaughtErrors()

Expand All @@ -19,4 +19,5 @@ const result1 = await atlas.query.continents({ name: true })
show(result1)

const result2 = await atlas.query.continentsOrThrow({ name: true })
// ^^^^^^^
result2 // This line will never be reached because of thrown error.
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': '1726346409373'
'x-sent-at-time': '1726357184256'
},
signal: undefined,
method: 'post',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dynamicValue } from '../$/helpers.js'
import { dynamicValue } from '../../$/helpers.js'

export const encode = (value: string) => {
return value.replace(/Headers {[^}]*}/s, dynamicValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
headers: Headers {
connection: 'keep-alive',
'content-length': '119',
'x-served-by': 'cache-yul1970038-YUL',
'x-served-by': 'cache-yul1970031-YUL',
'accept-ranges': 'bytes',
date: 'Sun, 08 Sep 2024 18:13:26 GMT',
'content-type': 'application/graphql-response+json; charset=utf-8',
Expand All @@ -32,13 +32,13 @@
'alt-svc': 'h3=":443"; ma=86400',
'access-control-allow-origin': '*',
'x-powered-by': 'Stellate',
age: '527204',
age: '537979',
'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000',
'x-cache': 'HIT',
'x-cache-hits': '33',
'x-cache-hits': '70',
'gcdn-cache': 'HIT',
'stellate-rate-limit-budget-remaining': '46',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=46;refill=60',
'stellate-rate-limit-budget-remaining': '35',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=35;refill=18',
'stellate-rate-limit-decision': 'pass',
'stellate-rate-limit-budget-required': '5',
'content-encoding': 'br'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
at async run (/some/path/to/client.ts:XX:XX)
at async executeRootType (/some/path/to/client.ts:XX:XX)
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output|output_envelope_envelope-error__envelope-error.ts:XX:XX) {
at async <anonymous> (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX) {
context: {
hookName: 'encode',
source: 'extension',
extensionName: 'anonymous'
},
cause: Error: Something went wrong.
at <anonymous> (/some/path/to/output|output_envelope_envelope-error__envelope-error.ts:XX:XX)
at <anonymous> (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX)
at applyBody (/some/path/to/main.ts:XX:XX)
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ ContextualError: There was an error in the extension "anonymous" (use named func
at async run (/some/path/to/client.ts:XX:XX)
at async executeRootType (/some/path/to/client.ts:XX:XX)
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output|output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX) {
at async <anonymous> (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX) {
context: {
hookName: 'encode',
source: 'extension',
extensionName: 'anonymous'
},
cause: Error: Something went wrong.
at <anonymous> (/some/path/to/output|output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX)
at <anonymous> (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX)
at applyBody (/some/path/to/main.ts:XX:XX)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ ContextualError: There was an error in the extension "anonymous" (use named func
at async run (/some/path/to/client.ts:XX:XX)
at async executeRootType (/some/path/to/client.ts:XX:XX)
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output|output_return-error.ts:XX:XX) {
at async <anonymous> (/some/path/to/output_return-error.ts:XX:XX) {
context: {
hookName: 'encode',
source: 'extension',
extensionName: 'anonymous'
},
cause: Error: Something went wrong.
at <anonymous> (/some/path/to/output|output_return-error.ts:XX:XX)
at <anonymous> (/some/path/to/output_return-error.ts:XX:XX)
at applyBody (/some/path/to/main.ts:XX:XX)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ContextualAggregateError: One or more errors in the execution result.
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX)
at async executeRootType (/some/path/to/client.ts:XX:XX)
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX) {
at async <anonymous> (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX) {
context: {},
cause: undefined,
errors: [
Expand Down Expand Up @@ -42,14 +42,14 @@ ContextualError: There was an error in the extension "anonymous" (use named func
at async run (/some/path/to/client.ts:XX:XX)
at async executeRootType (/some/path/to/client.ts:XX:XX)
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX) {
at async <anonymous> (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX) {
context: {
hookName: 'encode',
source: 'extension',
extensionName: 'anonymous'
},
cause: Error: Something went wrong.
at <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX)
at <anonymous> (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX)
at applyBody (/some/path/to/main.ts:XX:XX)
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX)
}
File renamed without changes.
Loading

0 comments on commit 060db41

Please sign in to comment.