polen 0.10.0-next.10 → 0.10.0-next.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/builder/builder.js +1 -1
- package/build/api/builder/builder.js.map +1 -1
- package/build/api/config/load.js +1 -1
- package/build/api/config/load.js.map +1 -1
- package/build/api/vite/plugins/build.js +1 -1
- package/build/api/vite/plugins/build.js.map +1 -1
- package/build/api/vite/plugins/core.d.ts.map +1 -1
- package/build/api/vite/plugins/core.js +0 -2
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/pages.js +1 -1
- package/build/api/vite/plugins/pages.js.map +1 -1
- package/build/exports/components.d.ts +4 -1
- package/build/exports/components.d.ts.map +1 -1
- package/build/exports/components.js +4 -1
- package/build/exports/components.js.map +1 -1
- package/build/lib/demos/config-schema.d.ts +6 -6
- package/build/lib/github-actions/runner.js +2 -2
- package/build/lib/github-actions/runner.js.map +1 -1
- package/build/lib/graphql-document/$$.d.ts +5 -0
- package/build/lib/graphql-document/$$.d.ts.map +1 -0
- package/build/lib/graphql-document/$$.js +5 -0
- package/build/lib/graphql-document/$$.js.map +1 -0
- package/build/lib/graphql-document/$.d.ts +2 -0
- package/build/lib/graphql-document/$.d.ts.map +1 -0
- package/build/lib/graphql-document/$.js +2 -0
- package/build/lib/graphql-document/$.js.map +1 -0
- package/build/lib/graphql-document/analysis.d.ts +44 -0
- package/build/lib/graphql-document/analysis.d.ts.map +1 -0
- package/build/lib/graphql-document/analysis.js +361 -0
- package/build/lib/graphql-document/analysis.js.map +1 -0
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts +42 -0
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts.map +1 -0
- package/build/lib/graphql-document/components/GraphQLDocument.js +173 -0
- package/build/lib/graphql-document/components/GraphQLDocument.js.map +1 -0
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts +7 -0
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts.map +1 -0
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js +45 -0
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js.map +1 -0
- package/build/lib/graphql-document/components/HoverTooltip.d.ts +35 -0
- package/build/lib/graphql-document/components/HoverTooltip.d.ts.map +1 -0
- package/build/lib/graphql-document/components/HoverTooltip.js +132 -0
- package/build/lib/graphql-document/components/HoverTooltip.js.map +1 -0
- package/build/lib/graphql-document/components/IdentifierLink.d.ts +37 -0
- package/build/lib/graphql-document/components/IdentifierLink.d.ts.map +1 -0
- package/build/lib/graphql-document/components/IdentifierLink.js +141 -0
- package/build/lib/graphql-document/components/IdentifierLink.js.map +1 -0
- package/build/lib/graphql-document/components/index.d.ts +5 -0
- package/build/lib/graphql-document/components/index.d.ts.map +1 -0
- package/build/lib/graphql-document/components/index.js +5 -0
- package/build/lib/graphql-document/components/index.js.map +1 -0
- package/build/lib/graphql-document/example.d.ts +25 -0
- package/build/lib/graphql-document/example.d.ts.map +1 -0
- package/build/lib/graphql-document/example.js +140 -0
- package/build/lib/graphql-document/example.js.map +1 -0
- package/build/lib/graphql-document/graphql-document.d.ts +35 -0
- package/build/lib/graphql-document/graphql-document.d.ts.map +1 -0
- package/build/lib/graphql-document/graphql-document.js +36 -0
- package/build/lib/graphql-document/graphql-document.js.map +1 -0
- package/build/lib/graphql-document/positioning-simple.d.ts +68 -0
- package/build/lib/graphql-document/positioning-simple.d.ts.map +1 -0
- package/build/lib/graphql-document/positioning-simple.js +197 -0
- package/build/lib/graphql-document/positioning-simple.js.map +1 -0
- package/build/lib/graphql-document/schema-context.d.ts +8 -0
- package/build/lib/graphql-document/schema-context.d.ts.map +1 -0
- package/build/lib/graphql-document/schema-context.js +11 -0
- package/build/lib/graphql-document/schema-context.js.map +1 -0
- package/build/lib/graphql-document/schema-integration-example.d.ts +27 -0
- package/build/lib/graphql-document/schema-integration-example.d.ts.map +1 -0
- package/build/lib/graphql-document/schema-integration-example.js +297 -0
- package/build/lib/graphql-document/schema-integration-example.js.map +1 -0
- package/build/lib/graphql-document/schema-integration.d.ts +135 -0
- package/build/lib/graphql-document/schema-integration.d.ts.map +1 -0
- package/build/lib/graphql-document/schema-integration.js +328 -0
- package/build/lib/graphql-document/schema-integration.js.map +1 -0
- package/build/lib/graphql-document/types.d.ts +117 -0
- package/build/lib/graphql-document/types.d.ts.map +1 -0
- package/build/lib/graphql-document/types.js +2 -0
- package/build/lib/graphql-document/types.js.map +1 -0
- package/build/template/components/ArgumentAnnotation.js +10 -0
- package/build/template/components/ArgumentAnnotation.js.map +1 -0
- package/build/template/components/ArgumentList.js +9 -0
- package/build/template/components/ArgumentList.js.map +1 -0
- package/build/template/components/ArgumentListAnnotation.js +15 -0
- package/build/template/components/ArgumentListAnnotation.js.map +1 -0
- package/build/template/components/Changelog.js +44 -0
- package/build/template/components/Changelog.js.map +1 -0
- package/build/template/components/{CodeBlock.jsx → CodeBlock.js} +4 -5
- package/build/template/components/{CodeBlock.jsx.map → CodeBlock.js.map} +1 -1
- package/build/template/components/CodeBlockEnhancer.d.ts +2 -0
- package/build/template/components/CodeBlockEnhancer.d.ts.map +1 -0
- package/build/template/components/CodeBlockEnhancer.js +175 -0
- package/build/template/components/CodeBlockEnhancer.js.map +1 -0
- package/build/template/components/DeprecationReason.js +9 -0
- package/build/template/components/DeprecationReason.js.map +1 -0
- package/build/template/components/Description.js +9 -0
- package/build/template/components/Description.js.map +1 -0
- package/build/template/components/Field.js +14 -0
- package/build/template/components/Field.js.map +1 -0
- package/build/template/components/{FieldList.jsx → FieldList.js} +4 -5
- package/build/template/components/FieldList.js.map +1 -0
- package/build/template/components/{FieldListSection.jsx → FieldListSection.js} +4 -6
- package/build/template/components/FieldListSection.js.map +1 -0
- package/build/template/components/HamburgerMenu.js +30 -0
- package/build/template/components/HamburgerMenu.js.map +1 -0
- package/build/template/components/Link.d.ts +1 -1
- package/build/template/components/{Link.jsx → Link.js} +4 -5
- package/build/template/components/Link.js.map +1 -0
- package/build/template/components/Logo.js +20 -0
- package/build/template/components/Logo.js.map +1 -0
- package/build/template/components/MDXComponents.d.ts +11 -0
- package/build/template/components/MDXComponents.d.ts.map +1 -0
- package/build/template/components/MDXComponents.js +70 -0
- package/build/template/components/MDXComponents.js.map +1 -0
- package/build/template/components/{Markdown.jsx → Markdown.js} +3 -2
- package/build/template/components/Markdown.js.map +1 -0
- package/build/template/components/MissingSchema.d.ts +1 -1
- package/build/template/components/MissingSchema.d.ts.map +1 -1
- package/build/template/components/MissingSchema.js +5 -0
- package/build/template/components/MissingSchema.js.map +1 -0
- package/build/template/components/NamedType.js +12 -0
- package/build/template/components/NamedType.js.map +1 -0
- package/build/template/components/NotFound.js +7 -0
- package/build/template/components/NotFound.js.map +1 -0
- package/build/template/components/{RadixLink.jsx → RadixLink.js} +1 -1
- package/build/template/components/RadixLink.js.map +1 -0
- package/build/template/components/TestComponent.d.ts +5 -0
- package/build/template/components/TestComponent.d.ts.map +1 -0
- package/build/template/components/TestComponent.js +7 -0
- package/build/template/components/TestComponent.js.map +1 -0
- package/build/template/components/Texts/{MinorHeading.jsx → MinorHeading.js} +4 -3
- package/build/template/components/Texts/MinorHeading.js.map +1 -0
- package/build/template/components/Texts/texts.js +1 -1
- package/build/template/components/Texts/texts.js.map +1 -1
- package/build/template/components/ThemeToggle.js +9 -0
- package/build/template/components/ThemeToggle.js.map +1 -0
- package/build/template/components/{TypeAnnotation.jsx → TypeAnnotation.js} +8 -18
- package/build/template/components/TypeAnnotation.js.map +1 -0
- package/build/template/components/TypeFieldsLinkList.js +9 -0
- package/build/template/components/TypeFieldsLinkList.js.map +1 -0
- package/build/template/components/TypeIndex.js +17 -0
- package/build/template/components/TypeIndex.js.map +1 -0
- package/build/template/components/content/$$.d.ts +1 -0
- package/build/template/components/content/$$.d.ts.map +1 -1
- package/build/template/components/content/$$.js +1 -0
- package/build/template/components/content/$$.js.map +1 -1
- package/build/template/components/content/GraphQLDocumentWithSchema.d.ts +8 -0
- package/build/template/components/content/GraphQLDocumentWithSchema.d.ts.map +1 -0
- package/build/template/components/content/GraphQLDocumentWithSchema.js +16 -0
- package/build/template/components/content/GraphQLDocumentWithSchema.js.map +1 -0
- package/build/template/components/content/GraphQLDocumentWrapper.d.ts +7 -0
- package/build/template/components/content/GraphQLDocumentWrapper.d.ts.map +1 -0
- package/build/template/components/content/GraphQLDocumentWrapper.js +62 -0
- package/build/template/components/content/GraphQLDocumentWrapper.js.map +1 -0
- package/build/template/components/graphql/graphql.d.ts +2 -2
- package/build/template/components/graphql/graphql.js +3 -0
- package/build/template/components/graphql/graphql.js.map +1 -0
- package/build/template/components/graphql/index.d.ts +1 -1
- package/build/template/components/graphql/index.js +1 -1
- package/build/template/components/graphql/index.js.map +1 -1
- package/build/template/components/graphql/{type-kind-icon.jsx → type-kind-icon.js} +3 -2
- package/build/template/components/graphql/type-kind-icon.js.map +1 -0
- package/build/template/components/graphql/type-link.js +11 -0
- package/build/template/components/graphql/type-link.js.map +1 -0
- package/build/template/components/sidebar/Sidebar.d.ts +1 -1
- package/build/template/components/sidebar/Sidebar.d.ts.map +1 -1
- package/build/template/components/sidebar/Sidebar.js +11 -0
- package/build/template/components/sidebar/Sidebar.js.map +1 -0
- package/build/template/components/sidebar/{SidebarItem.jsx → SidebarItem.js} +15 -32
- package/build/template/components/sidebar/SidebarItem.js.map +1 -0
- package/build/template/components/sidebar/ToggleButton.d.ts +1 -1
- package/build/template/components/sidebar/ToggleButton.d.ts.map +1 -1
- package/build/template/components/sidebar/ToggleButton.js +5 -0
- package/build/template/components/sidebar/ToggleButton.js.map +1 -0
- package/build/template/contexts/{ThemeContext.jsx → ThemeContext.js} +3 -4
- package/build/template/contexts/{ThemeContext.jsx.map → ThemeContext.js.map} +1 -1
- package/build/template/entry.client.d.ts +1 -0
- package/build/template/entry.client.d.ts.map +1 -1
- package/build/template/{entry.client.jsx → entry.client.js} +5 -6
- package/build/template/entry.client.js.map +1 -0
- package/build/template/routes/changelog.d.ts +1 -1
- package/build/template/routes/{changelog.jsx → changelog.js} +5 -4
- package/build/template/routes/changelog.js.map +1 -0
- package/build/template/routes/{index.jsx → index.js} +3 -2
- package/build/template/routes/index.js.map +1 -0
- package/build/template/routes/reference.$type.$field.d.ts +1 -1
- package/build/template/routes/{reference.$type.$field.jsx → reference.$type.$field.js} +6 -5
- package/build/template/routes/reference.$type.$field.js.map +1 -0
- package/build/template/routes/reference.$type.d.ts +1 -1
- package/build/template/routes/{reference.$type.jsx → reference.$type.js} +6 -5
- package/build/template/routes/reference.$type.js.map +1 -0
- package/build/template/routes/reference.d.ts +2 -2
- package/build/template/routes/reference.d.ts.map +1 -1
- package/build/template/routes/{reference.jsx → reference.js} +7 -12
- package/build/template/routes/reference.js.map +1 -0
- package/build/template/routes/root.d.ts +2 -2
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.js +286 -0
- package/build/template/routes/root.js.map +1 -0
- package/build/template/routes.js +5 -0
- package/build/template/routes.js.map +1 -0
- package/build/template/server/app.js +1 -1
- package/build/template/server/app.js.map +1 -1
- package/build/template/server/{render-page.jsx → render-page.js} +3 -4
- package/build/template/server/render-page.js.map +1 -0
- package/build/template/server/ssg/generate.js +1 -1
- package/build/template/server/ssg/generate.js.map +1 -1
- package/build/template/server/ssg/get-route-paths.js +1 -1
- package/build/template/server/ssg/get-route-paths.js.map +1 -1
- package/build/template/server/view.js +1 -1
- package/build/template/server/view.js.map +1 -1
- package/package.json +56 -8
- package/src/api/vite/plugins/core.ts +0 -3
- package/src/api/vite/plugins/pages.ts +1 -1
- package/src/exports/components.ts +4 -1
- package/src/lib/graphql-document/$$.ts +4 -0
- package/src/lib/graphql-document/$.test.ts +132 -0
- package/src/lib/graphql-document/$.ts +1 -0
- package/src/lib/graphql-document/README.md +102 -0
- package/src/lib/graphql-document/analysis.ts +415 -0
- package/src/lib/graphql-document/components/GraphQLDocument.tsx +284 -0
- package/src/lib/graphql-document/components/GraphQLDocument.unit.test.ts +188 -0
- package/src/lib/graphql-document/components/GraphQLDocumentWithSchema.tsx +70 -0
- package/src/lib/graphql-document/components/HoverTooltip.tsx +282 -0
- package/src/lib/graphql-document/components/IdentifierLink.tsx +221 -0
- package/src/lib/graphql-document/components/index.ts +4 -0
- package/src/lib/graphql-document/demo.md +155 -0
- package/src/lib/graphql-document/example.ts +163 -0
- package/src/lib/graphql-document/graphql-document.ts +37 -0
- package/src/lib/graphql-document/positioning-simple.test.ts +252 -0
- package/src/lib/graphql-document/positioning-simple.ts +271 -0
- package/src/lib/graphql-document/schema-context.tsx +20 -0
- package/src/lib/graphql-document/schema-integration-example.ts +341 -0
- package/src/lib/graphql-document/schema-integration.test.ts +365 -0
- package/src/lib/graphql-document/schema-integration.ts +497 -0
- package/src/lib/graphql-document/types.ts +129 -0
- package/src/template/components/ArgumentAnnotation.tsx +1 -1
- package/src/template/components/ArgumentList.tsx +1 -1
- package/src/template/components/ArgumentListAnnotation.tsx +2 -2
- package/src/template/components/CodeBlockEnhancer.tsx +192 -0
- package/src/template/components/DeprecationReason.tsx +1 -1
- package/src/template/components/Description.tsx +1 -1
- package/src/template/components/Field.tsx +4 -4
- package/src/template/components/FieldList.tsx +1 -1
- package/src/template/components/FieldListSection.tsx +1 -1
- package/src/template/components/Link.tsx +2 -2
- package/src/template/components/MDXComponents.tsx +101 -0
- package/src/template/components/NamedType.tsx +2 -2
- package/src/template/components/TestComponent.tsx +6 -0
- package/src/template/components/TypeAnnotation.tsx +1 -1
- package/src/template/components/TypeFieldsLinkList.tsx +1 -1
- package/src/template/components/TypeIndex.tsx +1 -1
- package/src/template/components/content/$$.ts +1 -0
- package/src/template/components/content/GraphQLDocumentWithSchema.tsx +18 -0
- package/src/template/components/content/GraphQLDocumentWrapper.tsx +82 -0
- package/src/template/components/graphql/graphql.tsx +2 -2
- package/src/template/components/graphql/index.ts +1 -1
- package/src/template/components/graphql/type-link.tsx +2 -2
- package/src/template/components/sidebar/SidebarItem.tsx +4 -4
- package/src/template/entry.client.tsx +2 -2
- package/src/template/routes/changelog.tsx +1 -1
- package/src/template/routes/reference.$type.$field.tsx +3 -3
- package/src/template/routes/reference.$type.tsx +3 -3
- package/src/template/routes/reference.tsx +6 -10
- package/src/template/routes/root.tsx +145 -5
- package/src/template/routes.tsx +1 -1
- package/src/template/server/app.ts +1 -1
- package/src/template/server/ssg/generate.ts +1 -1
- package/src/template/server/ssg/get-route-paths.ts +1 -1
- package/src/template/server/view.ts +1 -1
- package/src/template/styles/code-block.css +32 -0
- package/build/template/components/ArgumentAnnotation.jsx +0 -16
- package/build/template/components/ArgumentAnnotation.jsx.map +0 -1
- package/build/template/components/ArgumentList.jsx +0 -16
- package/build/template/components/ArgumentList.jsx.map +0 -1
- package/build/template/components/ArgumentListAnnotation.jsx +0 -23
- package/build/template/components/ArgumentListAnnotation.jsx.map +0 -1
- package/build/template/components/Changelog.jsx +0 -68
- package/build/template/components/Changelog.jsx.map +0 -1
- package/build/template/components/DeprecationReason.jsx +0 -10
- package/build/template/components/DeprecationReason.jsx.map +0 -1
- package/build/template/components/Description.jsx +0 -10
- package/build/template/components/Description.jsx.map +0 -1
- package/build/template/components/Field.jsx +0 -22
- package/build/template/components/Field.jsx.map +0 -1
- package/build/template/components/FieldList.jsx.map +0 -1
- package/build/template/components/FieldListSection.jsx.map +0 -1
- package/build/template/components/HamburgerMenu.jsx +0 -53
- package/build/template/components/HamburgerMenu.jsx.map +0 -1
- package/build/template/components/Link.jsx.map +0 -1
- package/build/template/components/Logo.jsx +0 -29
- package/build/template/components/Logo.jsx.map +0 -1
- package/build/template/components/Markdown.jsx.map +0 -1
- package/build/template/components/MissingSchema.jsx +0 -4
- package/build/template/components/MissingSchema.jsx.map +0 -1
- package/build/template/components/NamedType.jsx +0 -17
- package/build/template/components/NamedType.jsx.map +0 -1
- package/build/template/components/NotFound.jsx +0 -26
- package/build/template/components/NotFound.jsx.map +0 -1
- package/build/template/components/RadixLink.jsx.map +0 -1
- package/build/template/components/Texts/MinorHeading.jsx.map +0 -1
- package/build/template/components/ThemeToggle.jsx +0 -10
- package/build/template/components/ThemeToggle.jsx.map +0 -1
- package/build/template/components/TypeAnnotation.jsx.map +0 -1
- package/build/template/components/TypeFieldsLinkList.jsx +0 -17
- package/build/template/components/TypeFieldsLinkList.jsx.map +0 -1
- package/build/template/components/TypeIndex.jsx +0 -27
- package/build/template/components/TypeIndex.jsx.map +0 -1
- package/build/template/components/graphql/graphql.jsx +0 -3
- package/build/template/components/graphql/graphql.jsx.map +0 -1
- package/build/template/components/graphql/type-kind-icon.jsx.map +0 -1
- package/build/template/components/graphql/type-link.jsx +0 -16
- package/build/template/components/graphql/type-link.jsx.map +0 -1
- package/build/template/components/sidebar/Sidebar.jsx +0 -15
- package/build/template/components/sidebar/Sidebar.jsx.map +0 -1
- package/build/template/components/sidebar/SidebarItem.jsx.map +0 -1
- package/build/template/components/sidebar/ToggleButton.jsx +0 -6
- package/build/template/components/sidebar/ToggleButton.jsx.map +0 -1
- package/build/template/entry.client.jsx.map +0 -1
- package/build/template/routes/changelog.jsx.map +0 -1
- package/build/template/routes/index.jsx.map +0 -1
- package/build/template/routes/reference.$type.$field.jsx.map +0 -1
- package/build/template/routes/reference.$type.jsx.map +0 -1
- package/build/template/routes/reference.jsx.map +0 -1
- package/build/template/routes/root.jsx +0 -204
- package/build/template/routes/root.jsx.map +0 -1
- package/build/template/routes.jsx +0 -5
- package/build/template/routes.jsx.map +0 -1
- package/build/template/server/render-page.jsx.map +0 -1
@@ -0,0 +1,341 @@
|
|
1
|
+
/**
|
2
|
+
* Example usage of Schema Integration (Layer 2)
|
3
|
+
*
|
4
|
+
* Demonstrates how the schema integration layer resolves GraphQL identifiers
|
5
|
+
* against actual schemas, extracts documentation, and generates reference URLs.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { buildSchema } from 'graphql'
|
9
|
+
import { analyzeWithSchema, createPolenSchemaResolver } from './schema-integration.ts'
|
10
|
+
|
11
|
+
// Example schema - typical GraphQL API
|
12
|
+
const pokemonSchema = buildSchema(`
|
13
|
+
"""
|
14
|
+
A Pokémon character
|
15
|
+
"""
|
16
|
+
type Pokemon {
|
17
|
+
"""
|
18
|
+
The Pokémon's unique identifier
|
19
|
+
"""
|
20
|
+
id: ID!
|
21
|
+
|
22
|
+
"""
|
23
|
+
The Pokémon's name
|
24
|
+
"""
|
25
|
+
name: String!
|
26
|
+
|
27
|
+
"""
|
28
|
+
The Pokémon's type (e.g., Electric, Fire, Water)
|
29
|
+
"""
|
30
|
+
type: String!
|
31
|
+
|
32
|
+
"""
|
33
|
+
The Pokémon's abilities
|
34
|
+
"""
|
35
|
+
abilities(
|
36
|
+
"""
|
37
|
+
Maximum number of abilities to return
|
38
|
+
"""
|
39
|
+
first: Int = 5
|
40
|
+
): [Ability!]!
|
41
|
+
|
42
|
+
"""
|
43
|
+
@deprecated Use evolutionChain instead
|
44
|
+
"""
|
45
|
+
evolutions: [Pokemon!] @deprecated(reason: "Use evolutionChain instead")
|
46
|
+
}
|
47
|
+
|
48
|
+
"""
|
49
|
+
A special ability that Pokémon can have
|
50
|
+
"""
|
51
|
+
type Ability {
|
52
|
+
id: ID!
|
53
|
+
name: String!
|
54
|
+
description: String
|
55
|
+
isHidden: Boolean!
|
56
|
+
}
|
57
|
+
|
58
|
+
type Query {
|
59
|
+
"""
|
60
|
+
Get a Pokémon by ID
|
61
|
+
"""
|
62
|
+
pokemon(id: ID!): Pokemon
|
63
|
+
|
64
|
+
"""
|
65
|
+
Search for Pokémon by name
|
66
|
+
"""
|
67
|
+
searchPokemon(query: String!): [Pokemon!]!
|
68
|
+
}
|
69
|
+
`)
|
70
|
+
|
71
|
+
// Example GraphQL query with various constructs
|
72
|
+
const exampleQuery = `
|
73
|
+
query GetPokemonDetails($pokemonId: ID!, $abilityLimit: Int = 3) {
|
74
|
+
pokemon(id: $pokemonId) {
|
75
|
+
id
|
76
|
+
name
|
77
|
+
type
|
78
|
+
abilities(first: $abilityLimit) {
|
79
|
+
name
|
80
|
+
description
|
81
|
+
isHidden
|
82
|
+
}
|
83
|
+
evolutions # This field is deprecated
|
84
|
+
invalidField # This field doesn't exist
|
85
|
+
}
|
86
|
+
}
|
87
|
+
`
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Demonstrate basic schema resolution
|
91
|
+
*/
|
92
|
+
export const demonstrateSchemaResolution = () => {
|
93
|
+
console.log('🔗 Schema Integration Demo\n')
|
94
|
+
|
95
|
+
const resolver = createPolenSchemaResolver(pokemonSchema)
|
96
|
+
|
97
|
+
// Example identifiers (normally extracted from AST)
|
98
|
+
const testIdentifiers = [
|
99
|
+
{
|
100
|
+
name: 'Pokemon',
|
101
|
+
kind: 'Type' as const,
|
102
|
+
position: { start: 50, end: 57, line: 3, column: 5 },
|
103
|
+
schemaPath: ['Pokemon'],
|
104
|
+
context: { selectionPath: [] },
|
105
|
+
},
|
106
|
+
{
|
107
|
+
name: 'name',
|
108
|
+
kind: 'Field' as const,
|
109
|
+
position: { start: 75, end: 79, line: 4, column: 7 },
|
110
|
+
parentType: 'Pokemon',
|
111
|
+
schemaPath: ['Pokemon', 'name'],
|
112
|
+
context: { selectionPath: ['pokemon', 'name'] },
|
113
|
+
},
|
114
|
+
{
|
115
|
+
name: 'evolutions',
|
116
|
+
kind: 'Field' as const,
|
117
|
+
position: { start: 150, end: 160, line: 9, column: 7 },
|
118
|
+
parentType: 'Pokemon',
|
119
|
+
schemaPath: ['Pokemon', 'evolutions'],
|
120
|
+
context: { selectionPath: ['pokemon', 'evolutions'] },
|
121
|
+
},
|
122
|
+
{
|
123
|
+
name: 'first',
|
124
|
+
kind: 'Argument' as const,
|
125
|
+
position: { start: 120, end: 125, line: 6, column: 20 },
|
126
|
+
parentType: 'Pokemon',
|
127
|
+
schemaPath: ['Pokemon', 'abilities', 'first'],
|
128
|
+
context: { selectionPath: ['pokemon', 'abilities'] },
|
129
|
+
},
|
130
|
+
]
|
131
|
+
|
132
|
+
console.log('📋 Identifier Resolutions:\n')
|
133
|
+
|
134
|
+
for (const identifier of testIdentifiers) {
|
135
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
136
|
+
if (!resolution) continue
|
137
|
+
|
138
|
+
console.log(`🏷️ ${identifier.kind}: ${identifier.name}`)
|
139
|
+
console.log(` ✅ Exists: ${resolution.exists}`)
|
140
|
+
console.log(` 🔗 URL: ${resolution.referenceUrl}`)
|
141
|
+
|
142
|
+
if (resolution.documentation) {
|
143
|
+
console.log(` 📝 Type: ${resolution.documentation.typeInfo}`)
|
144
|
+
if (resolution.documentation.description) {
|
145
|
+
console.log(` 💬 Description: ${resolution.documentation.description}`)
|
146
|
+
}
|
147
|
+
if (resolution.documentation.defaultValue) {
|
148
|
+
console.log(` 🎯 Default: ${resolution.documentation.defaultValue}`)
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
if (resolution.deprecated) {
|
153
|
+
console.log(` ⚠️ DEPRECATED: ${resolution.deprecated.reason}`)
|
154
|
+
}
|
155
|
+
|
156
|
+
console.log()
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Demonstrate full schema-aware analysis
|
162
|
+
*/
|
163
|
+
export const demonstrateSchemaAwareAnalysis = () => {
|
164
|
+
console.log('🔍 Schema-Aware Analysis\n')
|
165
|
+
|
166
|
+
const result = analyzeWithSchema(exampleQuery, pokemonSchema)
|
167
|
+
|
168
|
+
console.log(`📊 Analysis Summary:`)
|
169
|
+
console.log(` • Valid GraphQL: ${result.analysis.isValid}`)
|
170
|
+
console.log(` • Total identifiers: ${result.analysis.identifiers.all.length}`)
|
171
|
+
console.log(` • Schema resolutions: ${result.resolutions.size}`)
|
172
|
+
console.log(` • Schema errors: ${result.schemaErrors.length}\n`)
|
173
|
+
|
174
|
+
// Show validation errors
|
175
|
+
if (result.schemaErrors.length > 0) {
|
176
|
+
console.log('🚨 Schema Validation Issues:\n')
|
177
|
+
for (const error of result.schemaErrors) {
|
178
|
+
const emoji = error.severity === 'error' ? '❌' : '⚠️'
|
179
|
+
const pos = `${error.identifier.position.line}:${error.identifier.position.column}`
|
180
|
+
console.log(` ${emoji} ${error.message} @ ${pos}`)
|
181
|
+
}
|
182
|
+
console.log()
|
183
|
+
}
|
184
|
+
|
185
|
+
// Show successful resolutions with hyperlink potential
|
186
|
+
console.log('🔗 Generated Hyperlinks:\n')
|
187
|
+
let linkCount = 0
|
188
|
+
|
189
|
+
for (const [key, resolution] of result.resolutions) {
|
190
|
+
if (resolution.exists && linkCount < 8) { // Show first 8 successful resolutions
|
191
|
+
const identifier = result.analysis.identifiers.all.find(id =>
|
192
|
+
key.startsWith(`${id.position.start}-${id.name}-${id.kind}`)
|
193
|
+
)
|
194
|
+
|
195
|
+
if (identifier) {
|
196
|
+
const pos = `${identifier.position.line}:${identifier.position.column}`
|
197
|
+
console.log(` 📍 ${identifier.name} (${identifier.kind}) → ${resolution.referenceUrl}`)
|
198
|
+
|
199
|
+
if (resolution.documentation?.description) {
|
200
|
+
const shortDesc = resolution.documentation.description.length > 50
|
201
|
+
? resolution.documentation.description.substring(0, 50) + '...'
|
202
|
+
: resolution.documentation.description
|
203
|
+
console.log(` 💬 "${shortDesc}"`)
|
204
|
+
}
|
205
|
+
|
206
|
+
linkCount++
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Demonstrate tooltip data extraction
|
214
|
+
*/
|
215
|
+
export const demonstrateTooltipData = () => {
|
216
|
+
console.log('\n💬 Tooltip Data Extraction\n')
|
217
|
+
|
218
|
+
const resolver = createPolenSchemaResolver(pokemonSchema)
|
219
|
+
|
220
|
+
// Simulate tooltip hover scenarios
|
221
|
+
const tooltipExamples = [
|
222
|
+
['Pokemon'],
|
223
|
+
['Pokemon', 'name'],
|
224
|
+
['Pokemon', 'abilities'],
|
225
|
+
['Pokemon', 'abilities', 'first'],
|
226
|
+
['Ability', 'isHidden'],
|
227
|
+
]
|
228
|
+
|
229
|
+
for (const schemaPath of tooltipExamples) {
|
230
|
+
const docs = resolver.getDocumentation(schemaPath)
|
231
|
+
if (docs) {
|
232
|
+
const pathStr = schemaPath.join(' → ')
|
233
|
+
console.log(`🏷️ ${pathStr}`)
|
234
|
+
console.log(` 📋 Type: ${docs.typeInfo}`)
|
235
|
+
|
236
|
+
if (docs.description) {
|
237
|
+
console.log(` 💬 Description: ${docs.description}`)
|
238
|
+
}
|
239
|
+
|
240
|
+
if (docs.defaultValue) {
|
241
|
+
console.log(` 🎯 Default: ${docs.defaultValue}`)
|
242
|
+
}
|
243
|
+
|
244
|
+
if (docs.deprecated) {
|
245
|
+
console.log(` ⚠️ DEPRECATED: ${docs.deprecated.reason}`)
|
246
|
+
}
|
247
|
+
|
248
|
+
console.log()
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* Demonstrate URL generation customization
|
255
|
+
*/
|
256
|
+
export const demonstrateCustomURLGeneration = () => {
|
257
|
+
console.log('🛠️ Custom URL Generation\n')
|
258
|
+
|
259
|
+
// Different resolver configurations
|
260
|
+
const configurations = [
|
261
|
+
{ name: 'Default', config: {} },
|
262
|
+
{ name: 'Custom Base Path', config: { basePath: '/docs/api' } },
|
263
|
+
{ name: 'No Fragments', config: { includeFragments: false } },
|
264
|
+
{ name: 'Custom + No Fragments', config: { basePath: '/schema', includeFragments: false } },
|
265
|
+
]
|
266
|
+
|
267
|
+
const testPaths = [
|
268
|
+
['Pokemon'],
|
269
|
+
['Pokemon', 'name'],
|
270
|
+
['Pokemon', 'abilities', 'first'],
|
271
|
+
]
|
272
|
+
|
273
|
+
for (const { name, config } of configurations) {
|
274
|
+
console.log(`📋 ${name}:`)
|
275
|
+
const resolver = createPolenSchemaResolver(pokemonSchema, config)
|
276
|
+
|
277
|
+
for (const path of testPaths) {
|
278
|
+
const url = resolver.generateReferenceLink(path)
|
279
|
+
console.log(` ${path.join(' → ')} → ${url}`)
|
280
|
+
}
|
281
|
+
console.log()
|
282
|
+
}
|
283
|
+
}
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Show integration with Polen's reference system
|
287
|
+
*/
|
288
|
+
export const demonstratePolenIntegration = () => {
|
289
|
+
console.log('🏗️ Polen Integration Preview\n')
|
290
|
+
|
291
|
+
// This demonstrates how the schema integration connects with Polen's existing systems
|
292
|
+
const result = analyzeWithSchema(exampleQuery, pokemonSchema, {
|
293
|
+
basePath: '/reference', // Polen's reference page base
|
294
|
+
includeFragments: true, // Enable field anchors
|
295
|
+
})
|
296
|
+
|
297
|
+
console.log('🔄 How this integrates with Polen:\n')
|
298
|
+
|
299
|
+
console.log('1. 📋 Schema Loading:')
|
300
|
+
console.log(" • Uses PROJECT_DATA.schema from Polen's build system")
|
301
|
+
console.log(' • Leverages existing schema processing pipeline')
|
302
|
+
console.log()
|
303
|
+
|
304
|
+
console.log('2. 🔗 Reference Links:')
|
305
|
+
console.log(" • Generates URLs matching Polen's /reference/* structure")
|
306
|
+
console.log(' • Works with existing TypeIndex and sidebar system')
|
307
|
+
console.log()
|
308
|
+
|
309
|
+
console.log('3. 💬 Documentation:')
|
310
|
+
console.log(' • Extracts descriptions for hover tooltips')
|
311
|
+
console.log(' • Provides type signatures for context')
|
312
|
+
console.log(' • Detects deprecation warnings')
|
313
|
+
console.log()
|
314
|
+
|
315
|
+
console.log('4. ✅ Validation:')
|
316
|
+
console.log(' • Build-time validation against actual schema')
|
317
|
+
console.log(' • Catches typos and invalid references')
|
318
|
+
console.log(' • Reports deprecation usage')
|
319
|
+
console.log()
|
320
|
+
|
321
|
+
// Show some example integrations
|
322
|
+
const validFields = Array.from(result.resolutions.values())
|
323
|
+
.filter(r => r.exists)
|
324
|
+
.slice(0, 3)
|
325
|
+
|
326
|
+
if (validFields.length > 0) {
|
327
|
+
console.log('📋 Example Reference Links:')
|
328
|
+
for (const resolution of validFields) {
|
329
|
+
console.log(` • ${resolution.referenceUrl}`)
|
330
|
+
}
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
// Run examples if executed directly
|
335
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
336
|
+
demonstrateSchemaResolution()
|
337
|
+
demonstrateSchemaAwareAnalysis()
|
338
|
+
demonstrateTooltipData()
|
339
|
+
demonstrateCustomURLGeneration()
|
340
|
+
demonstratePolenIntegration()
|
341
|
+
}
|
@@ -0,0 +1,365 @@
|
|
1
|
+
import { buildSchema } from 'graphql'
|
2
|
+
import { describe, expect, it } from 'vitest'
|
3
|
+
import { analyzeWithSchema, createPolenSchemaResolver } from './schema-integration.ts'
|
4
|
+
|
5
|
+
// Test schema
|
6
|
+
const testSchema = buildSchema(`
|
7
|
+
"""
|
8
|
+
A user in the system
|
9
|
+
"""
|
10
|
+
type User {
|
11
|
+
"""
|
12
|
+
The user's unique identifier
|
13
|
+
"""
|
14
|
+
id: ID!
|
15
|
+
|
16
|
+
"""
|
17
|
+
The user's full name
|
18
|
+
"""
|
19
|
+
name: String!
|
20
|
+
|
21
|
+
"""
|
22
|
+
The user's email address
|
23
|
+
"""
|
24
|
+
email: String!
|
25
|
+
|
26
|
+
"""
|
27
|
+
User's posts
|
28
|
+
"""
|
29
|
+
posts(
|
30
|
+
"""
|
31
|
+
Maximum number of posts to return
|
32
|
+
"""
|
33
|
+
first: Int = 10
|
34
|
+
|
35
|
+
"""
|
36
|
+
Filter posts after this cursor
|
37
|
+
"""
|
38
|
+
after: String
|
39
|
+
): [Post!]!
|
40
|
+
|
41
|
+
"""
|
42
|
+
@deprecated Use profile.avatar instead
|
43
|
+
"""
|
44
|
+
avatar: String @deprecated(reason: "Use profile.avatar instead")
|
45
|
+
}
|
46
|
+
|
47
|
+
"""
|
48
|
+
A blog post
|
49
|
+
"""
|
50
|
+
type Post {
|
51
|
+
id: ID!
|
52
|
+
title: String!
|
53
|
+
content: String!
|
54
|
+
author: User!
|
55
|
+
}
|
56
|
+
|
57
|
+
"""
|
58
|
+
Input for creating a user
|
59
|
+
"""
|
60
|
+
input CreateUserInput {
|
61
|
+
name: String!
|
62
|
+
email: String!
|
63
|
+
}
|
64
|
+
|
65
|
+
type Query {
|
66
|
+
"""
|
67
|
+
Get a user by ID
|
68
|
+
"""
|
69
|
+
user(id: ID!): User
|
70
|
+
|
71
|
+
"""
|
72
|
+
Search for users
|
73
|
+
"""
|
74
|
+
users(query: String!): [User!]!
|
75
|
+
}
|
76
|
+
|
77
|
+
type Mutation {
|
78
|
+
"""
|
79
|
+
Create a new user
|
80
|
+
"""
|
81
|
+
createUser(input: CreateUserInput!): User!
|
82
|
+
}
|
83
|
+
|
84
|
+
"""
|
85
|
+
Custom directive for validation
|
86
|
+
"""
|
87
|
+
directive @validate(pattern: String!) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
|
88
|
+
`)
|
89
|
+
|
90
|
+
describe('Schema Integration', () => {
|
91
|
+
describe('PolenSchemaResolver', () => {
|
92
|
+
const resolver = createPolenSchemaResolver(testSchema)
|
93
|
+
|
94
|
+
describe('Type Resolution', () => {
|
95
|
+
it('should resolve existing types', () => {
|
96
|
+
const identifier = {
|
97
|
+
name: 'User',
|
98
|
+
kind: 'Type' as const,
|
99
|
+
position: { start: 0, end: 4, line: 1, column: 1 },
|
100
|
+
schemaPath: ['User'],
|
101
|
+
context: { selectionPath: [] },
|
102
|
+
}
|
103
|
+
|
104
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
105
|
+
|
106
|
+
expect(resolution).toBeDefined()
|
107
|
+
expect(resolution!.exists).toBe(true)
|
108
|
+
expect(resolution!.referenceUrl).toBe('/reference/User')
|
109
|
+
expect(resolution!.documentation?.description).toContain('A user in the system')
|
110
|
+
expect(resolution!.documentation?.typeInfo).toBe('User')
|
111
|
+
})
|
112
|
+
|
113
|
+
it('should handle non-existent types', () => {
|
114
|
+
const identifier = {
|
115
|
+
name: 'NonExistentType',
|
116
|
+
kind: 'Type' as const,
|
117
|
+
position: { start: 0, end: 15, line: 1, column: 1 },
|
118
|
+
schemaPath: ['NonExistentType'],
|
119
|
+
context: { selectionPath: [] },
|
120
|
+
}
|
121
|
+
|
122
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
123
|
+
|
124
|
+
expect(resolution).toBeDefined()
|
125
|
+
expect(resolution!.exists).toBe(false)
|
126
|
+
expect(resolution!.referenceUrl).toBe('/reference/NonExistentType')
|
127
|
+
expect(resolution!.documentation).toBeUndefined()
|
128
|
+
})
|
129
|
+
})
|
130
|
+
|
131
|
+
describe('Field Resolution', () => {
|
132
|
+
it('should resolve existing fields', () => {
|
133
|
+
const identifier = {
|
134
|
+
name: 'name',
|
135
|
+
kind: 'Field' as const,
|
136
|
+
position: { start: 0, end: 4, line: 1, column: 1 },
|
137
|
+
parentType: 'User',
|
138
|
+
schemaPath: ['User', 'name'],
|
139
|
+
context: { selectionPath: ['name'] },
|
140
|
+
}
|
141
|
+
|
142
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
143
|
+
|
144
|
+
expect(resolution).toBeDefined()
|
145
|
+
expect(resolution!.exists).toBe(true)
|
146
|
+
expect(resolution!.referenceUrl).toBe('/reference/User#name')
|
147
|
+
expect(resolution!.documentation?.description).toContain("The user's full name")
|
148
|
+
expect(resolution!.documentation?.typeInfo).toBe('String!')
|
149
|
+
})
|
150
|
+
|
151
|
+
it('should detect deprecated fields', () => {
|
152
|
+
const identifier = {
|
153
|
+
name: 'avatar',
|
154
|
+
kind: 'Field' as const,
|
155
|
+
position: { start: 0, end: 6, line: 1, column: 1 },
|
156
|
+
parentType: 'User',
|
157
|
+
schemaPath: ['User', 'avatar'],
|
158
|
+
context: { selectionPath: ['avatar'] },
|
159
|
+
}
|
160
|
+
|
161
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
162
|
+
|
163
|
+
expect(resolution).toBeDefined()
|
164
|
+
expect(resolution!.exists).toBe(true)
|
165
|
+
expect(resolution!.deprecated).toBeDefined()
|
166
|
+
expect(resolution!.deprecated!.reason).toBe('Use profile.avatar instead')
|
167
|
+
})
|
168
|
+
|
169
|
+
it('should handle non-existent fields', () => {
|
170
|
+
const identifier = {
|
171
|
+
name: 'nonExistentField',
|
172
|
+
kind: 'Field' as const,
|
173
|
+
position: { start: 0, end: 16, line: 1, column: 1 },
|
174
|
+
parentType: 'User',
|
175
|
+
schemaPath: ['User', 'nonExistentField'],
|
176
|
+
context: { selectionPath: ['nonExistentField'] },
|
177
|
+
}
|
178
|
+
|
179
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
180
|
+
|
181
|
+
expect(resolution).toBeDefined()
|
182
|
+
expect(resolution!.exists).toBe(false)
|
183
|
+
expect(resolution!.referenceUrl).toBe('/reference/User#nonExistentField')
|
184
|
+
})
|
185
|
+
})
|
186
|
+
|
187
|
+
describe('Argument Resolution', () => {
|
188
|
+
it('should resolve field arguments', () => {
|
189
|
+
const identifier = {
|
190
|
+
name: 'first',
|
191
|
+
kind: 'Argument' as const,
|
192
|
+
position: { start: 0, end: 5, line: 1, column: 1 },
|
193
|
+
parentType: 'User',
|
194
|
+
schemaPath: ['User', 'posts', 'first'],
|
195
|
+
context: { selectionPath: ['posts'] },
|
196
|
+
}
|
197
|
+
|
198
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
199
|
+
|
200
|
+
expect(resolution).toBeDefined()
|
201
|
+
expect(resolution!.exists).toBe(true)
|
202
|
+
expect(resolution!.referenceUrl).toBe('/reference/User#posts-first')
|
203
|
+
expect(resolution!.documentation?.description).toContain('Maximum number of posts')
|
204
|
+
expect(resolution!.documentation?.typeInfo).toBe('Int')
|
205
|
+
expect(resolution!.documentation?.defaultValue).toBe('10')
|
206
|
+
})
|
207
|
+
})
|
208
|
+
|
209
|
+
describe('Variable Resolution', () => {
|
210
|
+
it('should handle variables', () => {
|
211
|
+
const identifier = {
|
212
|
+
name: 'id',
|
213
|
+
kind: 'Variable' as const,
|
214
|
+
position: { start: 0, end: 2, line: 1, column: 1 },
|
215
|
+
schemaPath: ['id'],
|
216
|
+
context: { selectionPath: [] },
|
217
|
+
}
|
218
|
+
|
219
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
220
|
+
|
221
|
+
expect(resolution).toBeDefined()
|
222
|
+
expect(resolution!.exists).toBe(true)
|
223
|
+
expect(resolution!.referenceUrl).toBe('/reference#variables')
|
224
|
+
expect(resolution!.documentation?.typeInfo).toBe('Variable')
|
225
|
+
expect(resolution!.documentation?.description).toBe('Query variable: $id')
|
226
|
+
})
|
227
|
+
})
|
228
|
+
|
229
|
+
describe('Directive Resolution', () => {
|
230
|
+
it('should resolve directives', () => {
|
231
|
+
const identifier = {
|
232
|
+
name: 'validate',
|
233
|
+
kind: 'Directive' as const,
|
234
|
+
position: { start: 0, end: 8, line: 1, column: 1 },
|
235
|
+
schemaPath: ['validate'],
|
236
|
+
context: { selectionPath: [] },
|
237
|
+
}
|
238
|
+
|
239
|
+
const resolution = resolver.resolveIdentifier(identifier)
|
240
|
+
|
241
|
+
expect(resolution).toBeDefined()
|
242
|
+
expect(resolution!.exists).toBe(true)
|
243
|
+
expect(resolution!.referenceUrl).toBe('/reference/directives#validate')
|
244
|
+
expect(resolution!.documentation?.description).toContain('Custom directive for validation')
|
245
|
+
})
|
246
|
+
})
|
247
|
+
|
248
|
+
describe('URL Generation', () => {
|
249
|
+
it('should generate correct URLs with custom base path', () => {
|
250
|
+
const customResolver = createPolenSchemaResolver(testSchema, {
|
251
|
+
basePath: '/docs/schema',
|
252
|
+
})
|
253
|
+
|
254
|
+
expect(customResolver.generateReferenceLink(['User'])).toBe('/docs/schema/User')
|
255
|
+
expect(customResolver.generateReferenceLink(['User', 'name'])).toBe('/docs/schema/User#name')
|
256
|
+
expect(customResolver.generateReferenceLink(['User', 'posts', 'first'])).toBe('/docs/schema/User#posts-first')
|
257
|
+
})
|
258
|
+
|
259
|
+
it('should handle fragment configuration', () => {
|
260
|
+
const noFragmentResolver = createPolenSchemaResolver(testSchema, {
|
261
|
+
includeFragments: false,
|
262
|
+
})
|
263
|
+
|
264
|
+
expect(noFragmentResolver.generateReferenceLink(['User', 'name'])).toBe('/reference/User')
|
265
|
+
})
|
266
|
+
})
|
267
|
+
|
268
|
+
describe('Documentation Extraction', () => {
|
269
|
+
it('should extract type documentation', () => {
|
270
|
+
const docs = resolver.getDocumentation(['User'])
|
271
|
+
|
272
|
+
expect(docs).toBeDefined()
|
273
|
+
expect(docs!.description).toContain('A user in the system')
|
274
|
+
expect(docs!.typeInfo).toBe('User')
|
275
|
+
})
|
276
|
+
|
277
|
+
it('should extract field documentation', () => {
|
278
|
+
const docs = resolver.getDocumentation(['User', 'email'])
|
279
|
+
|
280
|
+
expect(docs).toBeDefined()
|
281
|
+
expect(docs!.description).toContain("The user's email address")
|
282
|
+
expect(docs!.typeInfo).toBe('String!')
|
283
|
+
})
|
284
|
+
|
285
|
+
it('should extract argument documentation', () => {
|
286
|
+
const docs = resolver.getDocumentation(['User', 'posts', 'after'])
|
287
|
+
|
288
|
+
expect(docs).toBeDefined()
|
289
|
+
expect(docs!.description).toContain('Filter posts after this cursor')
|
290
|
+
expect(docs!.typeInfo).toBe('String')
|
291
|
+
})
|
292
|
+
})
|
293
|
+
|
294
|
+
describe('Schema Validation', () => {
|
295
|
+
it('should return all types', () => {
|
296
|
+
const types = resolver.getAllTypes()
|
297
|
+
|
298
|
+
expect(types).toContain('User')
|
299
|
+
expect(types).toContain('Post')
|
300
|
+
expect(types).toContain('CreateUserInput')
|
301
|
+
expect(types).toContain('Query')
|
302
|
+
expect(types).toContain('Mutation')
|
303
|
+
expect(types).not.toContain('__Schema') // Should filter introspection types
|
304
|
+
})
|
305
|
+
|
306
|
+
it('should check type existence', () => {
|
307
|
+
expect(resolver.typeExists('User')).toBe(true)
|
308
|
+
expect(resolver.typeExists('NonExistentType')).toBe(false)
|
309
|
+
})
|
310
|
+
})
|
311
|
+
})
|
312
|
+
|
313
|
+
describe('Schema-Aware Analysis', () => {
|
314
|
+
it('should perform complete schema-aware analysis', () => {
|
315
|
+
const source = `
|
316
|
+
query GetUser($id: ID!) {
|
317
|
+
user(id: $id) {
|
318
|
+
name
|
319
|
+
email
|
320
|
+
avatar
|
321
|
+
}
|
322
|
+
}
|
323
|
+
`
|
324
|
+
|
325
|
+
const result = analyzeWithSchema(source, testSchema)
|
326
|
+
|
327
|
+
expect(result.analysis.isValid).toBe(true)
|
328
|
+
expect(result.resolutions.size).toBeGreaterThan(0)
|
329
|
+
expect(result.schemaErrors.length).toBeGreaterThan(0)
|
330
|
+
|
331
|
+
// Should have deprecation warning for avatar field
|
332
|
+
const deprecationWarning = result.schemaErrors.find(
|
333
|
+
error => error.message.includes('avatar') && error.message.includes('deprecated'),
|
334
|
+
)
|
335
|
+
expect(deprecationWarning).toBeDefined()
|
336
|
+
expect(deprecationWarning!.severity).toBe('warning')
|
337
|
+
})
|
338
|
+
|
339
|
+
it('should resolve identifiers correctly', () => {
|
340
|
+
const source = `
|
341
|
+
query {
|
342
|
+
user(id: "123") {
|
343
|
+
name
|
344
|
+
}
|
345
|
+
}
|
346
|
+
`
|
347
|
+
|
348
|
+
const result = analyzeWithSchema(source, testSchema)
|
349
|
+
|
350
|
+
// Find the name field resolution
|
351
|
+
const nameField = result.analysis.identifiers.all.find(
|
352
|
+
id => id.name === 'name' && id.kind === 'Field',
|
353
|
+
)
|
354
|
+
expect(nameField).toBeDefined()
|
355
|
+
|
356
|
+
const nameResolutionKey = `${nameField!.position.start}-${nameField!.name}-${nameField!.kind}`
|
357
|
+
const nameResolution = result.resolutions.get(nameResolutionKey)
|
358
|
+
|
359
|
+
expect(nameResolution).toBeDefined()
|
360
|
+
expect(nameResolution!.exists).toBe(true)
|
361
|
+
expect(nameResolution!.referenceUrl).toBe('/reference/User#name')
|
362
|
+
expect(nameResolution!.documentation?.typeInfo).toBe('String!')
|
363
|
+
})
|
364
|
+
})
|
365
|
+
})
|