Variables
Const create
create: Create = (<T>(stateCreator: StateCreator<T>) => {console.log('zustand create mock');// to support a curried version of createreturn typeof stateCreator === 'function'? createUncurried(stateCreator): createUncurried;}) as typeof originalCreate
Const createStore
createStore: CreateStore = (<T>(stateCreator: StateCreator<T>) => {console.log('zustand createStore mock');// to support a curried version of createStorereturn typeof stateCreator === 'function'? createStoreUncurried(stateCreator): createStoreUncurried;}) as typeof originalCreateStore
Const docExplorerStore
doc
ExplorerStore: StoreApi<DocExplorerContextType> = createStore<DocExplorerContextType>((set, get) => ({explorerNavStack: INITIAL_NAV_STACK,actions: {push(item) {set(state => {const curr = state.explorerNavStack;const lastItem = curr.at(-1)!;const explorerNavStack: DocExplorerNavStack =// Avoid pushing duplicate itemslastItem.def === item.def ? curr : [...curr, item];return { explorerNavStack };});},pop() {set(state => {const curr = state.explorerNavStack;const explorerNavStack =curr.length > 1 ? (curr.slice(0, -1) as DocExplorerNavStack) : curr;return { explorerNavStack };});},reset() {set(state => {const curr = state.explorerNavStack;const explorerNavStack = curr.length === 1 ? curr : INITIAL_NAV_STACK;return { explorerNavStack };});},resolveSchemaReferenceToNavItem(schemaReference) {if (!schemaReference) {return;}const { push } = get().actions;switch (schemaReference.kind) {case 'Type': {push({name: schemaReference.type.name,def: schemaReference.type,});break;}case 'Field': {push({name: schemaReference.field.name,def: schemaReference.field,});break;}case 'Argument': {if (schemaReference.field) {push({name: schemaReference.field.name,def: schemaReference.field,});}break;}case 'EnumValue': {if (schemaReference.type) {push({name: schemaReference.type.name,def: schemaReference.type,});}break;}}},rebuildNavStackWithSchema(schema: GraphQLSchema) {set(state => {const oldNavStack = state.explorerNavStack;if (oldNavStack.length === 1) {return state;}// Spread is neededconst newNavStack: DocExplorerNavStack = [...INITIAL_NAV_STACK];let lastEntity:| GraphQLNamedType| GraphQLField<unknown, unknown>| null = null;for (const item of oldNavStack) {if (item === INITIAL_NAV_STACK[0]) {// No need to copy the initial itemcontinue;}if (item.def) {// If item.def isn't a named type, it must be a field, inputField, or argumentif (isNamedType(item.def)) {// The type needs to be replaced with the new schema type of the same nameconst newType = schema.getType(item.def.name);if (newType) {newNavStack.push({name: item.name,def: newType,});lastEntity = newType;} else {// This type no longer exists; the stack cannot be built beyond herebreak;}} else if (lastEntity === null) {// We can't have a sub-entity if we have no entity; stop rebuilding the nav stackbreak;} else if (isObjectType(lastEntity) ||isInputObjectType(lastEntity)) {// item.def must be a Field / input field; replace with the new field of the same nameconst field = lastEntity.getFields()[item.name];if (field) {newNavStack.push({name: item.name,def: field,});} else {// This field no longer exists; the stack cannot be built beyond herebreak;}} else if (isScalarType(lastEntity) ||isEnumType(lastEntity) ||isInterfaceType(lastEntity) ||isUnionType(lastEntity)) {// These don't (currently) have non-type sub-entries; something has gone wrong.// Handle gracefully by discontinuing rebuilding the stack.break;} else {// lastEntity must be a field (because it's not a named type)const field: GraphQLField<unknown, unknown> = lastEntity;// Thus item.def must be an argument, so find the same named argument in the new schemaif (field.args.some(a => a.name === item.name)) {newNavStack.push({name: item.name,def: field,});} else {// This argument no longer exists; the stack cannot be built beyond herebreak;}}} else {lastEntity = null;newNavStack.push(item);}}return { explorerNavStack: newNavStack };});},},}),)
Const storeResetFns
storeResetFns: Set<() => void> = new Set<() => void>()
@graphiql/plugin-doc-explorer