Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extension entrypoints #1219

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/30_gql/gql_gql-document-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/

import { parse } from 'graphql'
import { Opentelemetry, Throws } from '../../src/entrypoints/extensions.js'
import { Opentelemetry } from '../../src/entrypoints/extensions/opentelemetry/runtime.js'
import { Throws } from '../../src/entrypoints/extensions/throws/runtime.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This example shows how to use the Introspection extension to easily introspect your schema.
*/

import { Introspection } from '../../src/entrypoints/extensions.js'
import { Introspection } from '../../src/entrypoints/extensions/introspection/runtime.js'
import { Pokemon } from '../../tests/_/schemas/pokemon/graffle/__.js'
import { interceptAndShowUncaughtErrors, show } from '../$/show.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
import { Opentelemetry } from '../../src/entrypoints/extensions.js'
import { Opentelemetry } from '../../src/entrypoints/extensions/opentelemetry/runtime.js'
import { Pokemon } from '../../tests/_/schemas/pokemon/graffle/__.js'
import { interceptAndShowOutput, show } from '../$/helpers.js'

Expand Down
2 changes: 1 addition & 1 deletion examples/60_extension/extension_throws__throws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This example shows how to use the Throws extension to throw errors for one-off cases.
*/

import { Throws } from '../../src/entrypoints/extensions.js'
import { Throws } from '../../src/entrypoints/extensions/throws/runtime.js'
import { Pokemon } from '../../tests/_/schemas/pokemon/graffle/__.js'
import { interceptAndShowUncaughtErrors, show } from '../$/show.js'

Expand Down
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': '1729696838476'
'x-sent-at-time': '1729824583010'
},
signal: undefined,
method: 'post',
Expand Down
4 changes: 1 addition & 3 deletions examples/__outputs__/20_output/output_envelope.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
{ name: 'Weedle' }
]
},
errors: undefined,
extensions: undefined,
response: Response {
status: 200,
statusText: 'OK',
headers: Headers {
'content-type': 'application/graphql-response+json; charset=utf-8',
'content-length': '142',
date: 'Wed, 23 Oct 2024 15:20:39 GMT',
date: 'Fri, 25 Oct 2024 02:49:44 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
parentId: 'fdbedbd147dc630c',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: 'f1eb7799e82ca59a',
traceState: undefined,
name: 'encode',
id: '4f8b5fccd96cc062',
id: 'bb6b0c035e3cbc85',
kind: 0,
timestamp: 1729696839648000,
duration: 1705.875,
timestamp: 1729824584441000,
duration: 1365.042,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -29,18 +29,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
parentId: 'fdbedbd147dc630c',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: 'f1eb7799e82ca59a',
traceState: undefined,
name: 'pack',
id: 'a2cb6c68bb391b81',
id: '996cd2f8c264080a',
kind: 0,
timestamp: 1729696839652000,
duration: 16711.541,
timestamp: 1729824584444000,
duration: 12774.667,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -53,18 +53,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
parentId: 'fdbedbd147dc630c',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: 'f1eb7799e82ca59a',
traceState: undefined,
name: 'exchange',
id: '95bc25186061869d',
id: '3ad972c399fb8ec2',
kind: 0,
timestamp: 1729696839669000,
duration: 21608.417,
timestamp: 1729824584458000,
duration: 21008.167,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -77,18 +77,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
parentId: 'fdbedbd147dc630c',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: 'f1eb7799e82ca59a',
traceState: undefined,
name: 'unpack',
id: 'f33a840d705729c6',
id: 'bbdb7c3156b126e9',
kind: 0,
timestamp: 1729696839691000,
duration: 1755.75,
timestamp: 1729824584479000,
duration: 1927.291,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -101,18 +101,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
parentId: 'fdbedbd147dc630c',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: 'f1eb7799e82ca59a',
traceState: undefined,
name: 'decode',
id: 'd5abeead8c05a053',
id: 'e311421c9b0a3a5d',
kind: 0,
timestamp: 1729696839693000,
duration: 313.709,
timestamp: 1729824584481000,
duration: 221.916,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -125,18 +125,18 @@
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
'telemetry.sdk.version': '1.27.0'
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd',
traceId: '3b96fa441684458a1d46a660a7980d58',
parentId: undefined,
traceState: undefined,
name: 'request',
id: 'fdbedbd147dc630c',
id: 'f1eb7799e82ca59a',
kind: 0,
timestamp: 1729696839647000,
duration: 46403,
timestamp: 1729824584440000,
duration: 40916.625,
attributes: {},
status: { code: 0 },
events: [],
Expand Down
29 changes: 27 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,34 @@
"default": "./build/entrypoints/generator.js"
}
},
"./extensions": {
"./extensions/upload": {
"import": {
"default": "./build/entrypoints/extensions.js"
"default": "./build/entrypoints/extensions/upload/runtime.js"
}
},
"./extensions/throws": {
"import": {
"default": "./build/entrypoints/extensions/throws/runtime.js"
}
},
"./extensions/opentelemetry": {
"import": {
"default": "./build/entrypoints/extensions/opentelemetry/runtime.js"
}
},
"./extensions/introspection": {
"import": {
"default": "./build/entrypoints/extensions/introspection/runtime.js"
}
},
"./extensions/schema-errors": {
"import": {
"default": "./build/entrypoints/extensions/schema-errors/runtime.js"
}
},
"./extensions/schema-errors/generator": {
"import": {
"default": "./build/entrypoints/extensions/schema-errors/gentime.js"
}
},
"./client": {
Expand Down
8 changes: 8 additions & 0 deletions scripts/generate-examples-derivatives/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ const generateExampleLinksSnippets = async (examplesTransformed: ExampleTransfor
const transformRewriteGraffleImports = (example: Example) => {
const newContent = example.file.content
.replaceAll(/from '.+\/tests\/_\/schemas\/(.*)\/graffle\/(.+)\.js'/g, `from './$1/$2.js'`)
.replaceAll(
/from '.*entrypoints\/extensions\/(.*?)\/runtime.js'/g,
`from 'graffle/extensions/$1'`,
)
.replaceAll(
/from '.*entrypoints\/extensions\/(.*?)\/gentime.js'/g,
`from 'graffle/extensions/$1/generator'`,
)
.replaceAll(
/from '.*entrypoints\/main.js'/g,
`from 'graffle'`,
Expand Down
5 changes: 0 additions & 5 deletions src/entrypoints/extensions.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/entrypoints/extensions/introspection/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Introspection } from '../../../extensions/Introspection/Introspection.js'
1 change: 1 addition & 0 deletions src/entrypoints/extensions/opentelemetry/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Opentelemetry } from '../../../extensions/Opentelemetry/Opentelemetry.js'
Empty file.
Empty file.
1 change: 1 addition & 0 deletions src/entrypoints/extensions/schema-errors/gentime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SchemaErrors } from '../../../extensions/SchemaErrors/gentime.js'
1 change: 1 addition & 0 deletions src/entrypoints/extensions/schema-errors/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SchemaErrors } from '../../../extensions/SchemaErrors/runtime.js'
1 change: 1 addition & 0 deletions src/entrypoints/extensions/throws/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Throws } from '../../../extensions/Throws/Throws.js'
1 change: 1 addition & 0 deletions src/entrypoints/extensions/upload/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Upload } from '../../../extensions/Upload/Upload.js'
2 changes: 1 addition & 1 deletion src/extensions/Introspection/Introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createConfig, type Input } from './config.js'
* @example
*
* ```ts
* import { Introspection } from 'graffle/extensions'
* import { Introspection } from 'graffle/extensions/introspection'
*
* const graffle = new Graffle({
* schema: 'http://localhost:3000/graphql',
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/Opentelemetry/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pnpm add @opentelemetry/api

```ts twoslash
import { Graffle } from 'graffle'
import { Opentelemetry } from 'graffle/extensions'
import { Opentelemetry } from 'graffle/extensions/opentelemetry'

const graffle = Graffle.create({ schema: '...' }).use(Opentelemetry())
```
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/SchemaErrors/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This extension requires generation and also itself extends the generator. You mu
```ts
// graffle.config.ts

import { SchemaErrors } from 'graffle/extensions'
import { SchemaErrors } from 'graffle/extensions/schema-errors/generator'
import { Generator } from 'graffle/generator'

export default Generator
Expand All @@ -20,7 +20,7 @@ export default Generator
```ts twoslash
// your/app/code.ts
import { Graffle } from 'graffle'
import { SchemaErrors } from 'graffle/extensions'
import { SchemaErrors } from 'graffle/extensions/schema-errors'

const graffle = Graffle.create({ schema: '...' }).use(SchemaErrors())
```
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/SchemaErrors/tests/SchemaError.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expectTypeOf, test } from 'vitest'
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import { type Extension } from '../../../layers/6_client/extension/extension.js'
import { SchemaErrors } from '../SchemaErrors.js'
import { SchemaErrors } from '../runtime.js'
import { GraffleSchemaErrors } from './fixture/graffle/__.js'

const g = GraffleSchemaErrors.create({ schema }).use(SchemaErrors())
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/SchemaErrors/tests/SchemaErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest'
import { db } from '../../../../tests/_/schemas/db.js'
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import type { Errors } from '../../../lib/errors/__.js'
import { SchemaErrors } from '../SchemaErrors.js'
import { SchemaErrors } from '../runtime.js'
import { GraffleSchemaErrors } from './fixture/graffle/__.js'

const graffle = GraffleSchemaErrors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { schema } from '../../../../../tests/_/schemas/kitchen-sink/schema.js'
import { Generator } from '../../../../entrypoints/generator.js'
import { SchemaErrors } from '../../generator.js'
import { SchemaErrors } from '../../gentime.js'

export default Generator
.configure({
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/Throws/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ graffle.throws().query.foo()

```ts twoslash
import { Graffle } from 'graffle'
import { Throws } from 'graffle/extensions'
import { Throws } from 'graffle/extensions/throws'

const graffle = Graffle.create({ schema: '...' }).use(Throws())
```
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/Upload/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Adds support for [GraphQL Multipart Request](https://github.com/jaydenseric/grap

```ts twoslash
import { Graffle } from 'graffle'
import { Upload } from 'graffle/extensions'
import { Upload } from 'graffle/extensions/upload'

const graffle = Graffle.create({ schema: '...' }).use(Upload())
```
2 changes: 1 addition & 1 deletion src/generator/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import * as Path from 'node:path'
import { Graffle } from '../../entrypoints/__Graffle.js'
import { Introspection } from '../../entrypoints/extensions.js'
import { Introspection } from '../../extensions/Introspection/Introspection.js'
import { ConfigManager } from '../../lib/config-manager/__.js'
import { fileExists, isPathToADirectory, toAbsolutePath, toFilePath } from '../../lib/fs.js'
import { Grafaid } from '../../lib/grafaid/__.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- dprint-ignore-start -->
```ts twoslash
import { Introspection } from 'graffle/extensions'
import { Introspection } from 'graffle/extensions/introspection'
import { Pokemon } from './pokemon/__.js'

const pokemon = Pokemon.create().use(Introspection())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- dprint-ignore-start -->
```ts twoslash
import { Introspection } from 'graffle/extensions'
import { Introspection } from 'graffle/extensions/introspection'
import { Pokemon } from './pokemon/__.js'

const pokemon = Pokemon.create().use(Introspection())
Expand Down
Loading
Loading