@graphiql/plugin-doc-explorer 0.1.0-canary-24ce3ea2.0 → 0.1.1-canary-9a1c125e.0
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/dist/components/type-documentation.js +2 -2
- package/dist/components/type-documentation.js.map +1 -1
- package/dist/context.d.ts +4 -2
- package/dist/context.js +180 -156
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -299,7 +299,7 @@ const EnumValue = (t0) => {
|
|
|
299
299
|
}
|
|
300
300
|
let t2;
|
|
301
301
|
if ($[2] !== value.description) {
|
|
302
|
-
t2 = value.description
|
|
302
|
+
t2 = value.description ? /* @__PURE__ */ jsx(MarkdownContent, { type: "description", children: value.description }) : null;
|
|
303
303
|
$[2] = value.description;
|
|
304
304
|
$[3] = t2;
|
|
305
305
|
} else {
|
|
@@ -307,7 +307,7 @@ const EnumValue = (t0) => {
|
|
|
307
307
|
}
|
|
308
308
|
let t3;
|
|
309
309
|
if ($[4] !== value.deprecationReason) {
|
|
310
|
-
t3 = value.deprecationReason
|
|
310
|
+
t3 = value.deprecationReason ? /* @__PURE__ */ jsx(MarkdownContent, { type: "deprecation", children: value.deprecationReason }) : null;
|
|
311
311
|
$[4] = value.deprecationReason;
|
|
312
312
|
$[5] = t3;
|
|
313
313
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-documentation.js","sources":["../../src/components/type-documentation.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport {\n GraphQLEnumValue,\n GraphQLNamedType,\n isAbstractType,\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n} from 'graphql';\nimport { useSchemaStore, Button, MarkdownContent } from '@graphiql/react';\nimport { DocExplorerFieldDef } from '../context';\nimport { Argument } from './argument';\nimport { DefaultValue } from './default-value';\nimport { DeprecationReason } from './deprecation-reason';\nimport { FieldLink } from './field-link';\nimport { ExplorerSection } from './section';\nimport { TypeLink } from './type-link';\nimport './type-documentation.css';\n\ntype TypeDocumentationProps = {\n /**\n * The type that should be rendered.\n */\n type: GraphQLNamedType;\n};\n\nexport const TypeDocumentation: FC<TypeDocumentationProps> = ({ type }) => {\n return isNamedType(type) ? (\n <>\n {type.description ? (\n <MarkdownContent type=\"description\">{type.description}</MarkdownContent>\n ) : null}\n <ImplementsInterfaces type={type} />\n <Fields type={type} />\n <EnumValues type={type} />\n <PossibleTypes type={type} />\n </>\n ) : null;\n};\n\nconst ImplementsInterfaces: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n if (!isObjectType(type)) {\n return null;\n }\n const interfaces = type.getInterfaces();\n return interfaces.length > 0 ? (\n <ExplorerSection title=\"Implements\">\n {type.getInterfaces().map(implementedInterface => (\n <div key={implementedInterface.name}>\n <TypeLink type={implementedInterface} />\n </div>\n ))}\n </ExplorerSection>\n ) : null;\n};\n\nconst Fields: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (\n !isObjectType(type) &&\n !isInterfaceType(type) &&\n !isInputObjectType(type)\n ) {\n return null;\n }\n\n const fieldMap = type.getFields();\n\n const fields: DocExplorerFieldDef[] = [];\n const deprecatedFields: DocExplorerFieldDef[] = [];\n\n for (const field of Object.keys(fieldMap).map(name => fieldMap[name])) {\n if (field.deprecationReason) {\n deprecatedFields.push(field);\n } else {\n fields.push(field);\n }\n }\n\n return (\n <>\n {fields.length > 0 ? (\n <ExplorerSection title=\"Fields\">\n {fields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedFields.length > 0 ? (\n showDeprecated || fields.length === 0 ? (\n <ExplorerSection title=\"Deprecated Fields\">\n {deprecatedFields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Fields\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst Field: FC<{ field: DocExplorerFieldDef }> = ({ field }) => {\n const args =\n 'args' in field ? field.args.filter(arg => !arg.deprecationReason) : [];\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div>\n <FieldLink field={field} />\n {args.length > 0 ? (\n <>\n (\n <span>\n {args.map(arg =>\n args.length === 1 ? (\n <Argument key={arg.name} arg={arg} inline />\n ) : (\n <div\n key={arg.name}\n className=\"graphiql-doc-explorer-argument-multiple\"\n >\n <Argument arg={arg} inline />\n </div>\n ),\n )}\n </span>\n )\n </>\n ) : null}\n {': '}\n <TypeLink type={field.type} />\n <DefaultValue field={field} />\n </div>\n {field.description ? (\n <MarkdownContent type=\"description\" onlyShowFirstChild>\n {field.description}\n </MarkdownContent>\n ) : null}\n <DeprecationReason>{field.deprecationReason}</DeprecationReason>\n </div>\n );\n};\n\nconst EnumValues: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (!isEnumType(type)) {\n return null;\n }\n\n const values: GraphQLEnumValue[] = [];\n const deprecatedValues: GraphQLEnumValue[] = [];\n for (const value of type.getValues()) {\n if (value.deprecationReason) {\n deprecatedValues.push(value);\n } else {\n values.push(value);\n }\n }\n\n return (\n <>\n {values.length > 0 ? (\n <ExplorerSection title=\"Enum Values\">\n {values.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedValues.length > 0 ? (\n showDeprecated || values.length === 0 ? (\n <ExplorerSection title=\"Deprecated Enum Values\">\n {deprecatedValues.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Values\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst EnumValue: FC<{ value: GraphQLEnumValue }> = ({ value }) => {\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div className=\"graphiql-doc-explorer-enum-value\">{value.name}</div>\n {value.description && (\n <MarkdownContent type=\"description\">\n {value.description}\n </MarkdownContent>\n )}\n {value.deprecationReason && (\n <MarkdownContent type=\"deprecation\">\n {value.deprecationReason}\n </MarkdownContent>\n )}\n </div>\n );\n};\n\nconst PossibleTypes: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const { schema } = useSchemaStore();\n if (!schema || !isAbstractType(type)) {\n return null;\n }\n return (\n <ExplorerSection\n title={isInterfaceType(type) ? 'Implementations' : 'Possible Types'}\n >\n {schema.getPossibleTypes(type).map(possibleType => (\n <div key={possibleType.name}>\n <TypeLink type={possibleType} />\n </div>\n ))}\n </ExplorerSection>\n );\n};\n"],"names":["TypeDocumentation","t0","$","_c","type","t1","isNamedType","description","ImplementsInterfaces","isObjectType","getInterfaces","interfaces","t2","length","map","_temp","Fields","showDeprecated","setShowDeprecated","useState","Symbol","for","handleShowDeprecated","isInterfaceType","isInputObjectType","deprecatedFields","fields","fieldMap","getFields","field","Object","keys","name","deprecationReason","push","_temp2","t3","_temp3","t4","Field","args","filter","_temp4","arg_0","arg","t5","t6","t7","t8","t9","EnumValues","isEnumType","deprecatedValues","values","value","getValues","_temp5","_temp6","EnumValue","PossibleTypes","schema","useSchemaStore","isAbstractType","getPossibleTypes","_temp7","implementedInterface","field_0","field_1","value_0","value_1","possibleType"],"mappings":";;;;;;;;;;;;AA4BO,MAAMA,oBAAgDC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AAAQI,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAC7DE,SAAAA,YAAYF,IAAI,IAElBA,qBAAAA,UAAAA,EAAAA,UAAAA;AAAAA,MAAAA,KAAIG,cACF,oBAAA,iBAAA,EAAqB,MAAA,eAAeH,UAAAA,KAA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B;AAAA;AAzBL,SAAAyB,OAAAY,SAAA;AAAA,SAiCpC,oBAAA,WAAA,EAAkCf,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AA+BJ,SAAAgC,OAAAM,cAAA;AAU9C,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,mBAAY,CAAA,KADpBA,aAAYtC,IAEtB;AAAM;"}
|
|
1
|
+
{"version":3,"file":"type-documentation.js","sources":["../../src/components/type-documentation.tsx"],"sourcesContent":["import { FC, useState } from 'react';\nimport {\n GraphQLEnumValue,\n GraphQLNamedType,\n isAbstractType,\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n} from 'graphql';\nimport { useSchemaStore, Button, MarkdownContent } from '@graphiql/react';\nimport { DocExplorerFieldDef } from '../context';\nimport { Argument } from './argument';\nimport { DefaultValue } from './default-value';\nimport { DeprecationReason } from './deprecation-reason';\nimport { FieldLink } from './field-link';\nimport { ExplorerSection } from './section';\nimport { TypeLink } from './type-link';\nimport './type-documentation.css';\n\ntype TypeDocumentationProps = {\n /**\n * The type that should be rendered.\n */\n type: GraphQLNamedType;\n};\n\nexport const TypeDocumentation: FC<TypeDocumentationProps> = ({ type }) => {\n return isNamedType(type) ? (\n <>\n {type.description ? (\n <MarkdownContent type=\"description\">{type.description}</MarkdownContent>\n ) : null}\n <ImplementsInterfaces type={type} />\n <Fields type={type} />\n <EnumValues type={type} />\n <PossibleTypes type={type} />\n </>\n ) : null;\n};\n\nconst ImplementsInterfaces: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n if (!isObjectType(type)) {\n return null;\n }\n const interfaces = type.getInterfaces();\n return interfaces.length > 0 ? (\n <ExplorerSection title=\"Implements\">\n {type.getInterfaces().map(implementedInterface => (\n <div key={implementedInterface.name}>\n <TypeLink type={implementedInterface} />\n </div>\n ))}\n </ExplorerSection>\n ) : null;\n};\n\nconst Fields: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (\n !isObjectType(type) &&\n !isInterfaceType(type) &&\n !isInputObjectType(type)\n ) {\n return null;\n }\n\n const fieldMap = type.getFields();\n\n const fields: DocExplorerFieldDef[] = [];\n const deprecatedFields: DocExplorerFieldDef[] = [];\n\n for (const field of Object.keys(fieldMap).map(name => fieldMap[name])) {\n if (field.deprecationReason) {\n deprecatedFields.push(field);\n } else {\n fields.push(field);\n }\n }\n\n return (\n <>\n {fields.length > 0 ? (\n <ExplorerSection title=\"Fields\">\n {fields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedFields.length > 0 ? (\n showDeprecated || fields.length === 0 ? (\n <ExplorerSection title=\"Deprecated Fields\">\n {deprecatedFields.map(field => (\n <Field key={field.name} field={field} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Fields\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst Field: FC<{ field: DocExplorerFieldDef }> = ({ field }) => {\n const args =\n 'args' in field ? field.args.filter(arg => !arg.deprecationReason) : [];\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div>\n <FieldLink field={field} />\n {args.length > 0 ? (\n <>\n (\n <span>\n {args.map(arg =>\n args.length === 1 ? (\n <Argument key={arg.name} arg={arg} inline />\n ) : (\n <div\n key={arg.name}\n className=\"graphiql-doc-explorer-argument-multiple\"\n >\n <Argument arg={arg} inline />\n </div>\n ),\n )}\n </span>\n )\n </>\n ) : null}\n {': '}\n <TypeLink type={field.type} />\n <DefaultValue field={field} />\n </div>\n {field.description ? (\n <MarkdownContent type=\"description\" onlyShowFirstChild>\n {field.description}\n </MarkdownContent>\n ) : null}\n <DeprecationReason>{field.deprecationReason}</DeprecationReason>\n </div>\n );\n};\n\nconst EnumValues: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const [showDeprecated, setShowDeprecated] = useState(false);\n const handleShowDeprecated = () => {\n setShowDeprecated(true);\n };\n\n if (!isEnumType(type)) {\n return null;\n }\n\n const values: GraphQLEnumValue[] = [];\n const deprecatedValues: GraphQLEnumValue[] = [];\n for (const value of type.getValues()) {\n if (value.deprecationReason) {\n deprecatedValues.push(value);\n } else {\n values.push(value);\n }\n }\n\n return (\n <>\n {values.length > 0 ? (\n <ExplorerSection title=\"Enum Values\">\n {values.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : null}\n {deprecatedValues.length > 0 ? (\n showDeprecated || values.length === 0 ? (\n <ExplorerSection title=\"Deprecated Enum Values\">\n {deprecatedValues.map(value => (\n <EnumValue key={value.name} value={value} />\n ))}\n </ExplorerSection>\n ) : (\n <Button type=\"button\" onClick={handleShowDeprecated}>\n Show Deprecated Values\n </Button>\n )\n ) : null}\n </>\n );\n};\n\nconst EnumValue: FC<{ value: GraphQLEnumValue }> = ({ value }) => {\n return (\n <div className=\"graphiql-doc-explorer-item\">\n <div className=\"graphiql-doc-explorer-enum-value\">{value.name}</div>\n {value.description ? (\n <MarkdownContent type=\"description\">\n {value.description}\n </MarkdownContent>\n ) : null}\n {value.deprecationReason ? (\n <MarkdownContent type=\"deprecation\">\n {value.deprecationReason}\n </MarkdownContent>\n ) : null}\n </div>\n );\n};\n\nconst PossibleTypes: FC<{ type: GraphQLNamedType }> = ({ type }) => {\n const { schema } = useSchemaStore();\n if (!schema || !isAbstractType(type)) {\n return null;\n }\n return (\n <ExplorerSection\n title={isInterfaceType(type) ? 'Implementations' : 'Possible Types'}\n >\n {schema.getPossibleTypes(type).map(possibleType => (\n <div key={possibleType.name}>\n <TypeLink type={possibleType} />\n </div>\n ))}\n </ExplorerSection>\n );\n};\n"],"names":["TypeDocumentation","t0","$","_c","type","t1","isNamedType","description","ImplementsInterfaces","isObjectType","getInterfaces","interfaces","t2","length","map","_temp","Fields","showDeprecated","setShowDeprecated","useState","Symbol","for","handleShowDeprecated","isInterfaceType","isInputObjectType","deprecatedFields","fields","fieldMap","getFields","field","Object","keys","name","deprecationReason","push","_temp2","t3","_temp3","t4","Field","args","filter","_temp4","arg_0","arg","t5","t6","t7","t8","t9","EnumValues","isEnumType","deprecatedValues","values","value","getValues","_temp5","_temp6","EnumValue","PossibleTypes","schema","useSchemaStore","isAbstractType","getPossibleTypes","_temp7","implementedInterface","field_0","field_1","value_0","value_1","possibleType"],"mappings":";;;;;;;;;;;;AA4BO,MAAMA,oBAAgDC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AAAQI,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAC7DE,SAAAA,YAAYF,IAAI,IAElBA,qBAAAA,UAAAA,EAAAA,UAAAA;AAAAA,MAAAA,KAAIG,cACF,oBAAA,iBAAA,EAAqB,MAAA,eAAeH,UAAAA,KAAIG,aAAa,IACjD;AAAA,MACP,oBAAC,wBAA2BH,MAAI;AAAA,MAChC,oBAAC,UAAaA,MAAI;AAAA,MAClB,oBAAC,cAAiBA,MAAI;AAAA,MACtB,oBAAC,iBAAoBA,KAAI,CAAA;AAAA,IAAA,EAAA,CAAI,IAEzB;AAAAF,WAAAE;AAAAF,WAAAG;AAAAA,EAAAA,OAAA;AAAAA,SAAAH,EAAA,CAAA;AAAA,EAAA;AAVDG,SAAAA;AAUC;AAGV,MAAMG,uBAAuDP,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,EAAAA,IAAAH;AACvDQ,MAAAA,CAAAA,aAAaL,IAAI,GAAC;AAAA,WAAA;AAAA,EAAA;AAAAC,MAAAA;AAAAH,MAAAA,SAAAE,MAAA;AAGJC,SAAAD,KAAIM,cAAe;AAACR,WAAAE;AAAAF,WAAAG;AAAAA,EAAAA,OAAA;AAAAA,SAAAH,EAAA,CAAA;AAAA,EAAA;AAAvC,QAAAS,aAAmBN;AAAqBO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kC;AAAAA,EAAAA,OAAA;AAAAA,SAAAlC,EAAA,CAAA;AAAA,EAAA;AARlBkC,SAAAA;AAQkB;AA5LuC,SAAArB,MAAAkD,sBAAA;AAQrD,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,2BAAoB,CAAA,KAD5BA,qBAAoBjC,IAE9B;AAAM;AAMiC,SAAAG,OAAA+B,SAAA;AAAA,SAgClC,oBAAA,OAAA,EAA8BrC,OAAAA,QAAAA,GAAnBA,QAAKG,IAAuB;AAAA;AAhCL,SAAAK,OAAA8B,SAAA;AAAA,SAwChC,oBAAA,OAAA,EAA8BtC,OAAAA,QAAAA,GAAnBA,QAAKG,IAAuB;AAAA;AAaJ,SAAAU,OAAAE,KAAA;AAAA,SAEFA,CAAAA,IAAGX;AAAA;AAuCA,SAAAuB,OAAAY,SAAA;AAAA,SAyBtC,oBAAA,WAAA,EAAkCd,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AAzBL,SAAAyB,OAAAY,SAAA;AAAA,SAiCpC,oBAAA,WAAA,EAAkCf,OAAAA,QAAAA,GAAnBA,QAAKtB,IAAuB;AAAA;AA+BJ,SAAAgC,OAAAM,cAAA;AAU9C,SAAA,6BACE,UAAC,oBAAA,UAAA,EAAeA,mBAAY,CAAA,KADpBA,aAAYtC,IAEtB;AAAM;"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GraphQLArgument, GraphQLField, GraphQLInputField, GraphQLNamedType, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { FC, ReactNode, RefObject } from 'react';
|
|
3
3
|
import { SchemaContextType } from '@graphiql/react';
|
|
4
|
+
import { StoreApi } from 'zustand';
|
|
4
5
|
export declare type DocExplorerFieldDef = GraphQLField<unknown, unknown> | GraphQLInputField | GraphQLArgument;
|
|
5
6
|
export declare type DocExplorerNavStackItem = {
|
|
6
7
|
/**
|
|
@@ -45,7 +46,8 @@ export declare type DocExplorerContextType = {
|
|
|
45
46
|
rebuildNavStackWithSchema(schema: GraphQLSchema): void;
|
|
46
47
|
};
|
|
47
48
|
};
|
|
48
|
-
export declare
|
|
49
|
+
export declare function createDocExplorerStore(initialNavStackItem?: DocExplorerNavStackItem): StoreApi<DocExplorerContextType>;
|
|
50
|
+
export declare const DocExplorerContext: import('react').Context<RefObject<StoreApi<DocExplorerContextType>> | null>;
|
|
49
51
|
export declare const DocExplorerContextProvider: FC<{
|
|
50
52
|
children: ReactNode;
|
|
51
53
|
}>;
|
package/dist/context.js
CHANGED
|
@@ -1,204 +1,227 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
1
2
|
import { c } from "react-compiler-runtime";
|
|
2
3
|
import { isNamedType, isObjectType, isInputObjectType, isScalarType, isEnumType, isInterfaceType, isUnionType } from "graphql";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
+
import { createContext, useRef, useEffect, useContext } from "react";
|
|
4
5
|
import { useSchemaStore } from "@graphiql/react";
|
|
5
|
-
import {
|
|
6
|
-
|
|
6
|
+
import { createStore, useStore } from "zustand";
|
|
7
|
+
function createDocExplorerStore(initialNavStackItem = {
|
|
7
8
|
name: "Docs"
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const {
|
|
48
|
-
push
|
|
49
|
-
} = get().actions;
|
|
50
|
-
switch (schemaReference.kind) {
|
|
51
|
-
case "Type": {
|
|
52
|
-
push({
|
|
53
|
-
name: schemaReference.type.name,
|
|
54
|
-
def: schemaReference.type
|
|
55
|
-
});
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case "Field": {
|
|
59
|
-
push({
|
|
60
|
-
name: schemaReference.field.name,
|
|
61
|
-
def: schemaReference.field
|
|
62
|
-
});
|
|
63
|
-
break;
|
|
9
|
+
}) {
|
|
10
|
+
return createStore((set, get) => ({
|
|
11
|
+
explorerNavStack: [initialNavStackItem],
|
|
12
|
+
actions: {
|
|
13
|
+
push(item) {
|
|
14
|
+
set((state) => {
|
|
15
|
+
const curr = state.explorerNavStack;
|
|
16
|
+
const lastItem = curr.at(-1);
|
|
17
|
+
const explorerNavStack = (
|
|
18
|
+
// Avoid pushing duplicate items
|
|
19
|
+
lastItem.def === item.def ? curr : [...curr, item]
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
explorerNavStack
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
pop() {
|
|
27
|
+
set((state) => {
|
|
28
|
+
const curr = state.explorerNavStack;
|
|
29
|
+
const explorerNavStack = curr.length > 1 ? curr.slice(0, -1) : curr;
|
|
30
|
+
return {
|
|
31
|
+
explorerNavStack
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
reset() {
|
|
36
|
+
set((state) => {
|
|
37
|
+
const curr = state.explorerNavStack;
|
|
38
|
+
const explorerNavStack = curr.length === 1 ? curr : [initialNavStackItem];
|
|
39
|
+
return {
|
|
40
|
+
explorerNavStack
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
resolveSchemaReferenceToNavItem(schemaReference) {
|
|
45
|
+
if (!schemaReference) {
|
|
46
|
+
return;
|
|
64
47
|
}
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
const {
|
|
49
|
+
push
|
|
50
|
+
} = get().actions;
|
|
51
|
+
switch (schemaReference.kind) {
|
|
52
|
+
case "Type": {
|
|
67
53
|
push({
|
|
68
|
-
name: schemaReference.
|
|
69
|
-
def: schemaReference.
|
|
54
|
+
name: schemaReference.type.name,
|
|
55
|
+
def: schemaReference.type
|
|
70
56
|
});
|
|
57
|
+
break;
|
|
71
58
|
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
case "EnumValue": {
|
|
75
|
-
if (schemaReference.type) {
|
|
59
|
+
case "Field": {
|
|
76
60
|
push({
|
|
77
|
-
name: schemaReference.
|
|
78
|
-
def: schemaReference.
|
|
61
|
+
name: schemaReference.field.name,
|
|
62
|
+
def: schemaReference.field
|
|
79
63
|
});
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "Argument": {
|
|
67
|
+
if (schemaReference.field) {
|
|
68
|
+
push({
|
|
69
|
+
name: schemaReference.field.name,
|
|
70
|
+
def: schemaReference.field
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "EnumValue": {
|
|
76
|
+
if (schemaReference.type) {
|
|
77
|
+
push({
|
|
78
|
+
name: schemaReference.type.name,
|
|
79
|
+
def: schemaReference.type
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
80
83
|
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
rebuildNavStackWithSchema(schema) {
|
|
86
|
-
set((state) => {
|
|
87
|
-
const oldNavStack = state.explorerNavStack;
|
|
88
|
-
if (oldNavStack.length === 1) {
|
|
89
|
-
return oldNavStack;
|
|
90
84
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
},
|
|
86
|
+
rebuildNavStackWithSchema(schema) {
|
|
87
|
+
set((state) => {
|
|
88
|
+
const oldNavStack = state.explorerNavStack;
|
|
89
|
+
if (oldNavStack.length === 1) {
|
|
90
|
+
return oldNavStack;
|
|
96
91
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
const newNavStack = [initialNavStackItem];
|
|
93
|
+
let lastEntity = null;
|
|
94
|
+
for (const item of oldNavStack) {
|
|
95
|
+
if (item === initialNavStackItem) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (item.def) {
|
|
99
|
+
if (isNamedType(item.def)) {
|
|
100
|
+
const newType = schema.getType(item.def.name);
|
|
101
|
+
if (newType) {
|
|
102
|
+
newNavStack.push({
|
|
103
|
+
name: item.name,
|
|
104
|
+
def: newType
|
|
105
|
+
});
|
|
106
|
+
lastEntity = newType;
|
|
107
|
+
} else {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} else if (lastEntity === null) {
|
|
107
111
|
break;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
112
|
+
} else if (isObjectType(lastEntity) || isInputObjectType(lastEntity)) {
|
|
113
|
+
const field = lastEntity.getFields()[item.name];
|
|
114
|
+
if (field) {
|
|
115
|
+
newNavStack.push({
|
|
116
|
+
name: item.name,
|
|
117
|
+
def: field
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
} else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
119
123
|
break;
|
|
120
|
-
}
|
|
121
|
-
} else if (isScalarType(lastEntity) || isEnumType(lastEntity) || isInterfaceType(lastEntity) || isUnionType(lastEntity)) {
|
|
122
|
-
break;
|
|
123
|
-
} else {
|
|
124
|
-
const field = lastEntity;
|
|
125
|
-
if (field.args.some((a) => a.name === item.name)) {
|
|
126
|
-
newNavStack.push({
|
|
127
|
-
name: item.name,
|
|
128
|
-
def: field
|
|
129
|
-
});
|
|
130
124
|
} else {
|
|
131
|
-
|
|
125
|
+
const field = lastEntity;
|
|
126
|
+
if (field.args.some((a) => a.name === item.name)) {
|
|
127
|
+
newNavStack.push({
|
|
128
|
+
name: item.name,
|
|
129
|
+
def: field
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
132
134
|
}
|
|
135
|
+
} else {
|
|
136
|
+
lastEntity = null;
|
|
137
|
+
newNavStack.push(item);
|
|
133
138
|
}
|
|
134
|
-
} else {
|
|
135
|
-
lastEntity = null;
|
|
136
|
-
newNavStack.push(item);
|
|
137
139
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
}
|
|
140
|
+
return {
|
|
141
|
+
explorerNavStack: newNavStack
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
143
145
|
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
children
|
|
150
|
-
} = t0;
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
const DocExplorerContext = createContext(null);
|
|
149
|
+
const DocExplorerContextProvider = (props) => {
|
|
150
|
+
const $ = c(10);
|
|
151
151
|
const {
|
|
152
152
|
schema,
|
|
153
153
|
validationErrors,
|
|
154
154
|
schemaReference
|
|
155
155
|
} = useSchemaStore();
|
|
156
|
+
const storeRef = useRef(null);
|
|
157
|
+
if (storeRef.current === null) {
|
|
158
|
+
let t02;
|
|
159
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
160
|
+
t02 = createDocExplorerStore();
|
|
161
|
+
$[0] = t02;
|
|
162
|
+
} else {
|
|
163
|
+
t02 = $[0];
|
|
164
|
+
}
|
|
165
|
+
storeRef.current = t02;
|
|
166
|
+
}
|
|
167
|
+
let t0;
|
|
156
168
|
let t1;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
t1 = () => {
|
|
169
|
+
if ($[1] !== schemaReference) {
|
|
170
|
+
t0 = () => {
|
|
160
171
|
const {
|
|
161
172
|
resolveSchemaReferenceToNavItem
|
|
162
|
-
} =
|
|
173
|
+
} = storeRef.current.getState().actions;
|
|
163
174
|
resolveSchemaReferenceToNavItem(schemaReference);
|
|
164
175
|
};
|
|
165
|
-
|
|
166
|
-
$[
|
|
167
|
-
$[
|
|
168
|
-
$[
|
|
176
|
+
t1 = [schemaReference];
|
|
177
|
+
$[1] = schemaReference;
|
|
178
|
+
$[2] = t0;
|
|
179
|
+
$[3] = t1;
|
|
169
180
|
} else {
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
t0 = $[2];
|
|
182
|
+
t1 = $[3];
|
|
172
183
|
}
|
|
173
|
-
useEffect(
|
|
184
|
+
useEffect(t0, t1);
|
|
185
|
+
let t2;
|
|
174
186
|
let t3;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
t3 = () => {
|
|
187
|
+
if ($[4] !== schema || $[5] !== validationErrors) {
|
|
188
|
+
t2 = () => {
|
|
178
189
|
const {
|
|
179
190
|
reset,
|
|
180
191
|
rebuildNavStackWithSchema
|
|
181
|
-
} =
|
|
192
|
+
} = storeRef.current.getState().actions;
|
|
182
193
|
if (schema == null || validationErrors.length > 0) {
|
|
183
194
|
reset();
|
|
184
195
|
} else {
|
|
185
196
|
rebuildNavStackWithSchema(schema);
|
|
186
197
|
}
|
|
187
198
|
};
|
|
188
|
-
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
191
|
-
$[
|
|
192
|
-
$[
|
|
199
|
+
t3 = [schema, validationErrors];
|
|
200
|
+
$[4] = schema;
|
|
201
|
+
$[5] = validationErrors;
|
|
202
|
+
$[6] = t2;
|
|
203
|
+
$[7] = t3;
|
|
193
204
|
} else {
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
t2 = $[6];
|
|
206
|
+
t3 = $[7];
|
|
196
207
|
}
|
|
197
|
-
useEffect(
|
|
198
|
-
|
|
208
|
+
useEffect(t2, t3);
|
|
209
|
+
let t4;
|
|
210
|
+
if ($[8] !== props.children) {
|
|
211
|
+
t4 = /* @__PURE__ */ jsx(DocExplorerContext.Provider, { value: storeRef, children: props.children });
|
|
212
|
+
$[8] = props.children;
|
|
213
|
+
$[9] = t4;
|
|
214
|
+
} else {
|
|
215
|
+
t4 = $[9];
|
|
216
|
+
}
|
|
217
|
+
return t4;
|
|
199
218
|
};
|
|
200
219
|
function useDocExplorerStore(selector) {
|
|
201
|
-
|
|
220
|
+
const store = useContext(DocExplorerContext);
|
|
221
|
+
if (!store) {
|
|
222
|
+
throw new Error("Missing `DocExplorerContextProvider` in the tree");
|
|
223
|
+
}
|
|
224
|
+
return useStore(store.current, selector);
|
|
202
225
|
}
|
|
203
226
|
const useDocExplorer = () => {
|
|
204
227
|
return useDocExplorerStore(_temp);
|
|
@@ -213,8 +236,9 @@ function _temp2(state) {
|
|
|
213
236
|
return state.actions;
|
|
214
237
|
}
|
|
215
238
|
export {
|
|
239
|
+
DocExplorerContext,
|
|
216
240
|
DocExplorerContextProvider,
|
|
217
|
-
|
|
241
|
+
createDocExplorerStore,
|
|
218
242
|
useDocExplorer,
|
|
219
243
|
useDocExplorerActions
|
|
220
244
|
};
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type {\n GraphQLArgument,\n GraphQLField,\n GraphQLInputField,\n GraphQLNamedType,\n GraphQLSchema,\n} from 'graphql';\nimport {\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n isScalarType,\n isUnionType,\n} from 'graphql';\nimport { FC, ReactElement, ReactNode, useEffect } from 'react';\nimport { SchemaContextType, useSchemaStore } from '@graphiql/react';\nimport { createStore, useStore } from 'zustand';\n\nexport type DocExplorerFieldDef =\n | GraphQLField<unknown, unknown>\n | GraphQLInputField\n | GraphQLArgument;\n\nexport type DocExplorerNavStackItem = {\n /**\n * The name of the item.\n */\n name: string;\n /**\n * The definition object of the item, this can be a named type, a field, an\n * input field or an argument.\n */\n def?: GraphQLNamedType | DocExplorerFieldDef;\n};\n\n// There's always at least one item in the nav stack\nexport type DocExplorerNavStack = [\n DocExplorerNavStackItem,\n ...DocExplorerNavStackItem[],\n];\n\nexport type DocExplorerContextType = {\n /**\n * A stack of navigation items. The last item in the list is the current one.\n * This list always contains at least one item.\n */\n explorerNavStack: DocExplorerNavStack;\n actions: {\n /**\n * Push an item to the navigation stack.\n * @param item The item that should be pushed to the stack.\n */\n push(item: DocExplorerNavStackItem): void;\n /**\n * Pop the last item from the navigation stack.\n */\n pop(): void;\n /**\n * Reset the navigation stack to its initial state, this will remove all but\n * the initial stack item.\n */\n reset(): void;\n resolveSchemaReferenceToNavItem(\n schemaReference: SchemaContextType['schemaReference'],\n ): void;\n /**\n * Replace the nav stack with an updated version using the new schema.\n */\n rebuildNavStackWithSchema(schema: GraphQLSchema): void;\n };\n};\n\nconst INITIAL_NAV_STACK: DocExplorerNavStack = [{ name: 'Docs' }];\n\nexport const docExplorerStore = createStore<DocExplorerContextType>(\n (set, get) => ({\n explorerNavStack: INITIAL_NAV_STACK,\n actions: {\n push(item) {\n set(state => {\n const curr = state.explorerNavStack;\n const lastItem = curr.at(-1)!;\n const explorerNavStack: DocExplorerNavStack =\n // Avoid pushing duplicate items\n lastItem.def === item.def ? curr : [...curr, item];\n\n return { explorerNavStack };\n });\n },\n pop() {\n set(state => {\n const curr = state.explorerNavStack;\n\n const explorerNavStack =\n curr.length > 1 ? (curr.slice(0, -1) as DocExplorerNavStack) : curr;\n\n return { explorerNavStack };\n });\n },\n reset() {\n set(state => {\n const curr = state.explorerNavStack;\n const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;\n return { explorerNavStack };\n });\n },\n resolveSchemaReferenceToNavItem(schemaReference) {\n if (!schemaReference) {\n return;\n }\n const { push } = get().actions;\n switch (schemaReference.kind) {\n case 'Type': {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n break;\n }\n case 'Field': {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n break;\n }\n case 'Argument': {\n if (schemaReference.field) {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (schemaReference.type) {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n }\n break;\n }\n }\n },\n rebuildNavStackWithSchema(schema: GraphQLSchema) {\n set(state => {\n const oldNavStack = state.explorerNavStack;\n if (oldNavStack.length === 1) {\n return oldNavStack;\n }\n // Spread is needed\n const newNavStack: DocExplorerNavStack = [...INITIAL_NAV_STACK];\n let lastEntity:\n | GraphQLNamedType\n | GraphQLField<unknown, unknown>\n | null = null;\n for (const item of oldNavStack) {\n if (item === INITIAL_NAV_STACK[0]) {\n // No need to copy the initial item\n continue;\n }\n if (item.def) {\n // If item.def isn't a named type, it must be a field, inputField, or argument\n if (isNamedType(item.def)) {\n // The type needs to be replaced with the new schema type of the same name\n const newType = schema.getType(item.def.name);\n if (newType) {\n newNavStack.push({\n name: item.name,\n def: newType,\n });\n lastEntity = newType;\n } else {\n // This type no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (lastEntity === null) {\n // We can't have a sub-entity if we have no entity; stop rebuilding the nav stack\n break;\n } else if (\n isObjectType(lastEntity) ||\n isInputObjectType(lastEntity)\n ) {\n // item.def must be a Field / input field; replace with the new field of the same name\n const field = lastEntity.getFields()[item.name];\n if (field) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This field no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (\n isScalarType(lastEntity) ||\n isEnumType(lastEntity) ||\n isInterfaceType(lastEntity) ||\n isUnionType(lastEntity)\n ) {\n // These don't (currently) have non-type sub-entries; something has gone wrong.\n // Handle gracefully by discontinuing rebuilding the stack.\n break;\n } else {\n // lastEntity must be a field (because it's not a named type)\n const field: GraphQLField<unknown, unknown> = lastEntity;\n // Thus item.def must be an argument, so find the same named argument in the new schema\n if (field.args.some(a => a.name === item.name)) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This argument no longer exists; the stack cannot be built beyond here\n break;\n }\n }\n } else {\n lastEntity = null;\n newNavStack.push(item);\n }\n }\n return { explorerNavStack: newNavStack };\n });\n },\n },\n }),\n);\n\nexport const DocExplorerContextProvider: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { schema, validationErrors, schemaReference } = useSchemaStore();\n\n useEffect(() => {\n const { resolveSchemaReferenceToNavItem } =\n docExplorerStore.getState().actions;\n resolveSchemaReferenceToNavItem(schemaReference);\n }, [schemaReference]);\n\n useEffect(() => {\n const { reset, rebuildNavStackWithSchema } =\n docExplorerStore.getState().actions;\n\n // Whenever the schema changes, we must revalidate/replace the nav stack.\n if (schema == null || validationErrors.length > 0) {\n reset();\n } else {\n rebuildNavStackWithSchema(schema);\n }\n }, [schema, validationErrors]);\n\n return children as ReactElement;\n};\n\nfunction useDocExplorerStore<T>(\n selector: (state: DocExplorerContextType) => T,\n): T {\n return useStore(docExplorerStore, selector);\n}\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\nexport const useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"names":["INITIAL_NAV_STACK","name","docExplorerStore","createStore","set","get","explorerNavStack","actions","push","item","state","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","DocExplorerContextProvider","t0","$","_c","children","validationErrors","useSchemaStore","t1","t2","getState","useEffect","t3","t4","useDocExplorerStore","selector","useStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;AA0EA,MAAMA,oBAAyC,CAAC;AAAA,EAAEC,MAAM;AAAO,CAAC;AAEzD,MAAMC,mBAAmBC,YAC9B,CAACC,KAAKC,SAAS;AAAA,EACbC,kBAAkBN;AAAAA,EAClBO,SAAS;AAAA,IACPC,KAAKC,MAAM;AACTL,UAAIM,CAAS,UAAA;AACX,cAAMC,OAAOD,MAAMJ;AACbM,cAAAA,WAAWD,KAAKE,GAAG,EAAE;AACrBP,cAAAA;AAAAA;AAAAA,UAEJM,SAASE,QAAQL,KAAKK,MAAMH,OAAO,CAAC,GAAGA,MAAMF,IAAI;AAAA;AAE5C,eAAA;AAAA,UAAEH;AAAAA,QAAiB;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACAS,MAAM;AACJX,UAAIM,CAAS,UAAA;AACX,cAAMC,OAAOD,MAAMJ;AAEbA,cAAAA,mBACJK,KAAKK,SAAS,IAAKL,KAAKM,MAAM,GAAG,EAAE,IAA4BN;AAE1D,eAAA;AAAA,UAAEL;AAAAA,QAAiB;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACAY,QAAQ;AACNd,UAAIM,CAAS,UAAA;AACX,cAAMC,OAAOD,MAAMJ;AACnB,cAAMA,mBAAmBK,KAAKK,WAAW,IAAIL,OAAOX;AAC7C,eAAA;AAAA,UAAEM;AAAAA,QAAiB;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACAa,gCAAgCC,iBAAiB;AAC/C,UAAI,CAACA,iBAAiB;AACpB;AAAA,MAAA;AAEI,YAAA;AAAA,QAAEZ;AAAAA,MAAAA,IAASH,IAAME,EAAAA;AACvB,cAAQa,gBAAgBC,MAAI;AAAA,QAC1B,KAAK,QAAQ;AACN,eAAA;AAAA,YACHpB,MAAMmB,gBAAgBE,KAAKrB;AAAAA,YAC3Ba,KAAKM,gBAAgBE;A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;AAACwB,WAAAxB;AAAAwB,WAAAK;AAAAL,WAAAM;AAAAA,EAAAA,OAAA;AAAAD,SAAAL,EAAA,CAAA;AAAAM,SAAAN,EAAA,CAAA;AAAA,EAAA;AAJpBQ,YAAUH,IAIPC,EAAiB;AAACG,MAAAA;AAAAC,MAAAA;AAAA,MAAAV,EAAAnB,CAAAA,MAAAA,UAAAmB,SAAAG,kBAAA;AAEXM,SAAAA,MAAA;AACR,YAAA;AAAA,QAAAnC;AAAAA,QAAAM;AAAAA,MAAAA,IACEtB,iBAAAiD,SAAAA,EAA2B5C;AAAS,UAGlCkB,UAAc,QAAIsB,iBAAgB/B,SAAW,GAAA;AACzC,cAAA;AAAA,MAAA,OAAC;AAEPQ,kCAA0BC,MAAM;AAAA,MAAA;AAAA,IAAC;AAElC,SAAA,CAACA,QAAQsB,gBAAgB;AAACH,WAAAnB;AAAAmB,WAAAG;AAAAH,WAAAS;AAAAT,WAAAU;AAAAA,EAAAA,OAAA;AAAAD,SAAAT,EAAA,CAAA;AAAAU,SAAAV,EAAA,CAAA;AAAA,EAAA;AAV7BQ,YAAUC,IAUPC,EAA0B;AAEtBR,SAAAA;AAAwB;AAGjC,SAAAS,oBAAAC,UAAA;AAGSC,SAAAA,SAAAvD,kBAA2BsD,QAAQ;AAAC;AAGtC,MAAME,iBAAiBA,MAAA;AAAA,SAC5BH,oBAAAI,KAAmD;AAAC;AAC/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCL,oBAAAM,MAA0C;AAAC;AAHf,SAAAF,MAAAjD,OAAA;AAAA,SACCA,MAAKJ;AAAA;AACC,SAAAuD,OAAAnD,OAAA;AAAA,SACNA,MAAKH;AAAA;"}
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["import type {\n GraphQLArgument,\n GraphQLField,\n GraphQLInputField,\n GraphQLNamedType,\n GraphQLSchema,\n} from 'graphql';\nimport {\n isEnumType,\n isInputObjectType,\n isInterfaceType,\n isNamedType,\n isObjectType,\n isScalarType,\n isUnionType,\n} from 'graphql';\nimport {\n createContext,\n FC,\n ReactNode,\n RefObject,\n useContext,\n useEffect,\n useRef,\n} from 'react';\nimport { SchemaContextType, useSchemaStore } from '@graphiql/react';\nimport { createStore, StoreApi, useStore } from 'zustand';\n\nexport type DocExplorerFieldDef =\n | GraphQLField<unknown, unknown>\n | GraphQLInputField\n | GraphQLArgument;\n\nexport type DocExplorerNavStackItem = {\n /**\n * The name of the item.\n */\n name: string;\n /**\n * The definition object of the item, this can be a named type, a field, an\n * input field or an argument.\n */\n def?: GraphQLNamedType | DocExplorerFieldDef;\n};\n\n// There's always at least one item in the nav stack\nexport type DocExplorerNavStack = [\n DocExplorerNavStackItem,\n ...DocExplorerNavStackItem[],\n];\n\nexport type DocExplorerContextType = {\n /**\n * A stack of navigation items. The last item in the list is the current one.\n * This list always contains at least one item.\n */\n explorerNavStack: DocExplorerNavStack;\n actions: {\n /**\n * Push an item to the navigation stack.\n * @param item The item that should be pushed to the stack.\n */\n push(item: DocExplorerNavStackItem): void;\n /**\n * Pop the last item from the navigation stack.\n */\n pop(): void;\n /**\n * Reset the navigation stack to its initial state, this will remove all but\n * the initial stack item.\n */\n reset(): void;\n resolveSchemaReferenceToNavItem(\n schemaReference: SchemaContextType['schemaReference'],\n ): void;\n /**\n * Replace the nav stack with an updated version using the new schema.\n */\n rebuildNavStackWithSchema(schema: GraphQLSchema): void;\n };\n};\n\nexport function createDocExplorerStore(\n initialNavStackItem: DocExplorerNavStackItem = { name: 'Docs' },\n) {\n return createStore<DocExplorerContextType>((set, get) => ({\n explorerNavStack: [initialNavStackItem],\n actions: {\n push(item) {\n set(state => {\n const curr = state.explorerNavStack;\n const lastItem = curr.at(-1)!;\n const explorerNavStack: DocExplorerNavStack =\n // Avoid pushing duplicate items\n lastItem.def === item.def ? curr : [...curr, item];\n\n return { explorerNavStack };\n });\n },\n pop() {\n set(state => {\n const curr = state.explorerNavStack;\n\n const explorerNavStack =\n curr.length > 1 ? (curr.slice(0, -1) as DocExplorerNavStack) : curr;\n\n return { explorerNavStack };\n });\n },\n reset() {\n set(state => {\n const curr = state.explorerNavStack;\n const explorerNavStack: DocExplorerNavStack =\n curr.length === 1 ? curr : [initialNavStackItem];\n return { explorerNavStack };\n });\n },\n resolveSchemaReferenceToNavItem(schemaReference) {\n if (!schemaReference) {\n return;\n }\n const { push } = get().actions;\n switch (schemaReference.kind) {\n case 'Type': {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n break;\n }\n case 'Field': {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n break;\n }\n case 'Argument': {\n if (schemaReference.field) {\n push({\n name: schemaReference.field.name,\n def: schemaReference.field,\n });\n }\n break;\n }\n case 'EnumValue': {\n if (schemaReference.type) {\n push({\n name: schemaReference.type.name,\n def: schemaReference.type,\n });\n }\n break;\n }\n }\n },\n rebuildNavStackWithSchema(schema: GraphQLSchema) {\n set(state => {\n const oldNavStack = state.explorerNavStack;\n if (oldNavStack.length === 1) {\n return oldNavStack;\n }\n const newNavStack: DocExplorerNavStack = [initialNavStackItem];\n let lastEntity:\n | GraphQLNamedType\n | GraphQLField<unknown, unknown>\n | null = null;\n for (const item of oldNavStack) {\n if (item === initialNavStackItem) {\n // No need to copy the initial item\n continue;\n }\n if (item.def) {\n // If item.def isn't a named type, it must be a field, inputField, or argument\n if (isNamedType(item.def)) {\n // The type needs to be replaced with the new schema type of the same name\n const newType = schema.getType(item.def.name);\n if (newType) {\n newNavStack.push({\n name: item.name,\n def: newType,\n });\n lastEntity = newType;\n } else {\n // This type no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (lastEntity === null) {\n // We can't have a sub-entity if we have no entity; stop rebuilding the nav stack\n break;\n } else if (\n isObjectType(lastEntity) ||\n isInputObjectType(lastEntity)\n ) {\n // item.def must be a Field / input field; replace with the new field of the same name\n const field = lastEntity.getFields()[item.name];\n if (field) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This field no longer exists; the stack cannot be built beyond here\n break;\n }\n } else if (\n isScalarType(lastEntity) ||\n isEnumType(lastEntity) ||\n isInterfaceType(lastEntity) ||\n isUnionType(lastEntity)\n ) {\n // These don't (currently) have non-type sub-entries; something has gone wrong.\n // Handle gracefully by discontinuing rebuilding the stack.\n break;\n } else {\n // lastEntity must be a field (because it's not a named type)\n const field: GraphQLField<unknown, unknown> = lastEntity;\n // Thus item.def must be an argument, so find the same named argument in the new schema\n if (field.args.some(a => a.name === item.name)) {\n newNavStack.push({\n name: item.name,\n def: field,\n });\n } else {\n // This argument no longer exists; the stack cannot be built beyond here\n break;\n }\n }\n } else {\n lastEntity = null;\n newNavStack.push(item);\n }\n }\n return { explorerNavStack: newNavStack };\n });\n },\n },\n }));\n}\n\nexport const DocExplorerContext = createContext<RefObject<\n StoreApi<DocExplorerContextType>\n> | null>(null);\n\nexport const DocExplorerContextProvider: FC<{\n children: ReactNode;\n}> = props => {\n const { schema, validationErrors, schemaReference } = useSchemaStore();\n const storeRef = useRef<StoreApi<DocExplorerContextType>>(null!);\n\n if (storeRef.current === null) {\n storeRef.current = createDocExplorerStore();\n }\n\n useEffect(() => {\n const { resolveSchemaReferenceToNavItem } =\n storeRef.current.getState().actions;\n resolveSchemaReferenceToNavItem(schemaReference);\n }, [schemaReference]);\n\n useEffect(() => {\n const { reset, rebuildNavStackWithSchema } =\n storeRef.current.getState().actions;\n\n // Whenever the schema changes, we must revalidate/replace the nav stack.\n if (schema == null || validationErrors.length > 0) {\n reset();\n } else {\n rebuildNavStackWithSchema(schema);\n }\n }, [schema, validationErrors]);\n\n return (\n <DocExplorerContext.Provider value={storeRef}>\n {props.children}\n </DocExplorerContext.Provider>\n );\n};\n\nfunction useDocExplorerStore<T>(\n selector: (state: DocExplorerContextType) => T,\n): T {\n const store = useContext(DocExplorerContext);\n if (!store) {\n throw new Error('Missing `DocExplorerContextProvider` in the tree');\n }\n return useStore(store.current, selector);\n}\n\nexport const useDocExplorer = () =>\n useDocExplorerStore(state => state.explorerNavStack);\nexport const useDocExplorerActions = () =>\n useDocExplorerStore(state => state.actions);\n"],"names":["createDocExplorerStore","initialNavStackItem","name","createStore","set","get","explorerNavStack","actions","push","item","state","curr","lastItem","at","def","pop","length","slice","reset","resolveSchemaReferenceToNavItem","schemaReference","kind","type","field","rebuildNavStackWithSchema","schema","oldNavStack","newNavStack","lastEntity","isNamedType","newType","getType","isObjectType","isInputObjectType","getFields","isScalarType","isEnumType","isInterfaceType","isUnionType","args","some","a","DocExplorerContext","createContext","DocExplorerContextProvider","props","$","_c","validationErrors","useSchemaStore","storeRef","useRef","current","t0","Symbol","for","t1","getState","useEffect","t2","t3","t4","children","useDocExplorerStore","selector","store","useContext","Error","useStore","useDocExplorer","_temp","useDocExplorerActions","_temp2"],"mappings":";;;;;;AAkFO,SAASA,uBACdC,sBAA+C;AAAA,EAAEC,MAAM;AAAO,GAC9D;AACOC,SAAAA,YAAoC,CAACC,KAAKC,SAAS;AAAA,IACxDC,kBAAkB,CAACL,mBAAmB;AAAA,IACtCM,SAAS;AAAA,MACPC,KAAKC,MAAM;AACTL,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ;AACbM,gBAAAA,WAAWD,KAAKE,GAAG,EAAE;AACrBP,gBAAAA;AAAAA;AAAAA,YAEJM,SAASE,QAAQL,KAAKK,MAAMH,OAAO,CAAC,GAAGA,MAAMF,IAAI;AAAA;AAE5C,iBAAA;AAAA,YAAEH;AAAAA,UAAiB;AAAA,QAAA,CAC3B;AAAA,MACH;AAAA,MACAS,MAAM;AACJX,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ;AAEbA,gBAAAA,mBACJK,KAAKK,SAAS,IAAKL,KAAKM,MAAM,GAAG,EAAE,IAA4BN;AAE1D,iBAAA;AAAA,YAAEL;AAAAA,UAAiB;AAAA,QAAA,CAC3B;AAAA,MACH;AAAA,MACAY,QAAQ;AACNd,YAAIM,CAAS,UAAA;AACX,gBAAMC,OAAOD,MAAMJ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B;AAAAqB,WAAAE;AAAAF,WAAAa;AAAAb,WAAAc;AAAAA,EAAAA,OAAA;AAAAD,SAAAb,EAAA,CAAA;AAAAc,SAAAd,EAAA,CAAA;AAAA,EAAA;AAV7BY,YAAUC,IAUPC,EAA0B;AAACC,MAAAA;AAAA,MAAAf,EAAA,CAAA,MAAAD,MAAAiB,UAAA;AAG5BD,6BAAA,mBAAA,UAAA,EAAoCX,OAAO,UACxCL,gBAAKiB,UACR;AAA8B,MAAA,CAAA,IAAAjB,MAAAiB;AAAAhB,WAAAe;AAAAA,EAAAA,OAAA;AAAAA,SAAAf,EAAA,CAAA;AAAA,EAAA;AAF9Be,SAAAA;AAE8B;AAIlC,SAAAE,oBAAAC,UAAA;AAGEC,QAAAA,QAAcC,WAAAxB,kBAA6B;AAAE,MAAA,CACxCuB,OAAK;AAAAE,UAAAA,IAAAA,MACQ,kDAAkD;AAAA,EAAA;AAE7DC,SAAAA,SAASH,MAAKb,SAAUY,QAAQ;AAAC;AAGnC,MAAMK,iBAAiBA,MAAA;AAAA,SAC5BN,oBAAAO,KAAmD;AAAC;AAC/C,MAAMC,wBAAwBA,MAAA;AAAA,SACnCR,oBAAAS,MAA0C;AAAC;AAHf,SAAAF,MAAA5D,OAAA;AAAA,SACCA,MAAKJ;AAAA;AACC,SAAAkE,OAAA9D,OAAA;AAAA,SACNA,MAAKH;AAAA;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphiQLPlugin } from '@graphiql/react';
|
|
2
2
|
export * from './components';
|
|
3
|
-
export { DocExplorerContextProvider, useDocExplorer, useDocExplorerActions, } from './context';
|
|
3
|
+
export { DocExplorerContext, DocExplorerContextProvider, useDocExplorer, useDocExplorerActions, } from './context';
|
|
4
4
|
export type { DocExplorerContextType, DocExplorerFieldDef, DocExplorerNavStack, DocExplorerNavStackItem, } from './context';
|
|
5
5
|
export declare const DOC_EXPLORER_PLUGIN: GraphiQLPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { DocExplorerContextProvider, useDocExplorer, useDocExplorerActions } from "./context.js";
|
|
2
|
+
import { usePluginContext, DocsFilledIcon, DocsIcon } from "@graphiql/react";
|
|
3
|
+
import { DocExplorerContext, DocExplorerContextProvider, useDocExplorer, useDocExplorerActions } from "./context.js";
|
|
4
4
|
import { DocExplorer } from "./components/doc-explorer.js";
|
|
5
5
|
import { Argument } from "./components/argument.js";
|
|
6
6
|
import { DefaultValue } from "./components/default-value.js";
|
|
@@ -16,10 +16,8 @@ import { TypeLink } from "./components/type-link.js";
|
|
|
16
16
|
const DOC_EXPLORER_PLUGIN = {
|
|
17
17
|
title: "Documentation Explorer",
|
|
18
18
|
icon: function Icon() {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
} = usePluginStore();
|
|
22
|
-
return visiblePlugin === DOC_EXPLORER_PLUGIN ? /* @__PURE__ */ jsx(DocsFilledIcon, {}) : /* @__PURE__ */ jsx(DocsIcon, {});
|
|
19
|
+
const pluginContext = usePluginContext();
|
|
20
|
+
return (pluginContext == null ? void 0 : pluginContext.visiblePlugin) === DOC_EXPLORER_PLUGIN ? /* @__PURE__ */ jsx(DocsFilledIcon, {}) : /* @__PURE__ */ jsx(DocsIcon, {});
|
|
23
21
|
},
|
|
24
22
|
content: DocExplorer
|
|
25
23
|
};
|
|
@@ -30,6 +28,7 @@ export {
|
|
|
30
28
|
DeprecationReason,
|
|
31
29
|
Directive,
|
|
32
30
|
DocExplorer,
|
|
31
|
+
DocExplorerContext,
|
|
33
32
|
DocExplorerContextProvider,
|
|
34
33
|
ExplorerSection,
|
|
35
34
|
FieldDocumentation,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import {\n DocsFilledIcon,\n DocsIcon,\n GraphiQLPlugin,\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import {\n DocsFilledIcon,\n DocsIcon,\n GraphiQLPlugin,\n usePluginContext,\n} from '@graphiql/react';\nimport { DocExplorer } from './components';\n\nexport * from './components';\n\nexport {\n DocExplorerContext,\n DocExplorerContextProvider,\n useDocExplorer,\n useDocExplorerActions,\n} from './context';\n\nexport type {\n DocExplorerContextType,\n DocExplorerFieldDef,\n DocExplorerNavStack,\n DocExplorerNavStackItem,\n} from './context';\n\nexport const DOC_EXPLORER_PLUGIN: GraphiQLPlugin = {\n title: 'Documentation Explorer',\n icon: function Icon() {\n const pluginContext = usePluginContext();\n return pluginContext?.visiblePlugin === DOC_EXPLORER_PLUGIN ? (\n <DocsFilledIcon />\n ) : (\n <DocsIcon />\n );\n },\n content: DocExplorer,\n};\n"],"names":["DOC_EXPLORER_PLUGIN","title","icon","Icon","pluginContext","usePluginContext","visiblePlugin","content","DocExplorer"],"mappings":";;;;;;;;;;;;;;;AAwBO,MAAMA,sBAAsC;AAAA,EACjDC,OAAO;AAAA,EACPC,MAAM,SAASC,OAAO;AACpB,UAAMC,gBAAgBC,iBAAiB;AACvC,YAAOD,+CAAeE,mBAAkBN,0CACrC,gBAAiB,CAAA,CAAA,wBAEjB,UACF,EAAA;AAAA,EACH;AAAA,EACAO,SAASC;AACX;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphiql/plugin-doc-explorer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary-9a1c125e.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
45
|
-
"@graphiql/react": "^0.33.0-canary-
|
|
45
|
+
"@graphiql/react": "^0.33.0-canary-9a1c125e.0",
|
|
46
46
|
"@headlessui/react": "^2.2",
|
|
47
47
|
"zustand": "^5"
|
|
48
48
|
},
|