import { type SafeSqlFragment } from '@supabase/pg-meta' import type { ReactNode } from 'react' import { CodeBlock } from 'ui-patterns/CodeBlock' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' type IntrospectionMode = 'enable' | 'disable' interface ModeCopy { title: string confirmLabel: string confirmLabelLoading: string persistenceBullet: (schema: string) => ReactNode securityBullet: ReactNode } const COPY: Record = { enable: { title: 'Enable GraphQL introspection?', confirmLabel: 'Enable introspection', confirmLabelLoading: 'Enabling...', persistenceBullet: (_schema) => <>This setting persists until explicitly disabled., securityBullet: ( <> External actors will be able to introspect your schema using the anon key. ), }, disable: { title: 'Disable GraphQL introspection?', confirmLabel: 'Disable introspection', confirmLabelLoading: 'Disabling...', persistenceBullet: (_schema) => <>This setting persists until explicitly re-enabled., securityBullet: ( <> External actors will no longer be able to introspect your schema via the anon{' '} key. GraphiQL's docs explorer and autocomplete will stop working until introspection is re-enabled. ), }, } interface IntrospectionConfirmModalProps { mode: IntrospectionMode visible: boolean schema: string sql: SafeSqlFragment otherExistingKeys: string[] existingDirectiveIsMalformed: boolean isPending: boolean onCancel: () => void onConfirm: () => void } export const IntrospectionConfirmModal = ({ mode, visible, schema, sql, otherExistingKeys, existingDirectiveIsMalformed, isPending, onCancel, onConfirm, }: IntrospectionConfirmModalProps) => { const copy = COPY[mode] const hasPreservedOptions = otherExistingKeys.length > 0 return (
  • {copy.persistenceBullet(schema)}
  • {copy.securityBullet}
  • {hasPreservedOptions && (
  • Existing @graphql(...) options on this schema will be preserved:{' '} .
  • )} {existingDirectiveIsMalformed && (
  • The existing @graphql(...) directive on this schema could not be parsed and will be replaced by the statement below.
  • )}

The following statement will be executed:

{sql}
) } const PreservedOptionKeys = ({ keys }: { keys: string[] }) => ( <> {keys.map((k, i) => ( {i > 0 && ', '} {k} ))} )