IntrospectionEnabledNotice.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { useState } from 'react'
  2. import { Button } from 'ui'
  3. import { IntrospectionConfirmModal } from './IntrospectionConfirmModal'
  4. import { useSetIntrospection } from './useSetIntrospection'
  5. interface IntrospectionEnabledNoticeProps {
  6. schema: string
  7. currentSchemaComment: string | null | undefined
  8. onDisabled: () => void
  9. }
  10. export const IntrospectionEnabledNotice = ({
  11. schema,
  12. currentSchemaComment,
  13. onDisabled,
  14. }: IntrospectionEnabledNoticeProps) => {
  15. const [showConfirm, setShowConfirm] = useState(false)
  16. const { apply, isPending, sql, existingDirectiveIsMalformed, otherExistingKeys } =
  17. useSetIntrospection({
  18. schema,
  19. currentSchemaComment,
  20. enabled: false,
  21. onMutationSuccess: () => setShowConfirm(false),
  22. onInvalidated: onDisabled,
  23. })
  24. return (
  25. <>
  26. <div className="flex items-center justify-between gap-3 border-b bg-surface-100 px-4 py-2 text-xs text-foreground-light">
  27. <span>
  28. GraphQL introspection is enabled for this project, so schemas are discoverable through the
  29. API.
  30. </span>
  31. <Button type="default" size="tiny" onClick={() => setShowConfirm(true)}>
  32. Disable introspection
  33. </Button>
  34. </div>
  35. <IntrospectionConfirmModal
  36. mode="disable"
  37. visible={showConfirm}
  38. schema={schema}
  39. sql={sql}
  40. otherExistingKeys={otherExistingKeys}
  41. existingDirectiveIsMalformed={existingDirectiveIsMalformed}
  42. isPending={isPending}
  43. onCancel={() => setShowConfirm(false)}
  44. onConfirm={apply}
  45. />
  46. </>
  47. )
  48. }