Introduction.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { useParams } from 'common'
  2. import { DocSection } from '../../DocSection'
  3. import PublicSchemaNotEnabledAlert from '../../PublicSchemaNotEnabledAlert'
  4. import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'
  5. import { GeneratingTypes } from '@/components/interfaces/Docs/GeneratingTypes'
  6. import { InlineLink } from '@/components/ui/InlineLink'
  7. import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'
  8. interface IntroductionProps {
  9. selectedLang: 'bash' | 'js'
  10. }
  11. const Introduction = ({ selectedLang }: IntroductionProps) => {
  12. const { ref: projectRef } = useParams()
  13. const { data: config, isSuccess } = useProjectPostgrestConfigQuery({ projectRef })
  14. const isPublicSchemaEnabled = config?.db_schema
  15. .split(',')
  16. .map((name) => name.trim())
  17. .includes('public')
  18. return (
  19. <div className="flex flex-col flex-1">
  20. <DocSection
  21. title="Introduction"
  22. content={
  23. <p>
  24. All views and tables in the <code>public</code> schema and accessible by the active
  25. database role for a request are available for querying.
  26. </p>
  27. }
  28. snippets={isSuccess && !isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}
  29. />
  30. <DocSection
  31. title="Non-exposed tables"
  32. content={
  33. <p>
  34. If you don't want to expose tables in your API, simply add them to a different schema
  35. (not the <code>public</code> schema).
  36. </p>
  37. }
  38. />
  39. <GeneratingTypes selectedLang={selectedLang} />
  40. <DocSection
  41. title={
  42. <>
  43. GraphQL <span className="lowercase font-normal">vs</span> Briven
  44. </>
  45. }
  46. content={
  47. <>
  48. <p>
  49. If you have a GraphQL background, you might be wondering if you can fetch your data in
  50. a single round-trip. The answer is yes!
  51. </p>
  52. <p>
  53. The syntax is very similar. This example shows how you might achieve the same thing
  54. with Apollo GraphQL and Briven.
  55. </p>
  56. <h4 className="text-foreground-light mt-8 font-medium">Still want GraphQL?</h4>
  57. <p>
  58. If you still want to use GraphQL, you can. Briven provides you with a full Postgres
  59. database, so as long as your middleware can connect to the database then you can still
  60. use the tools you love. You can find the database connection details{' '}
  61. <InlineLink href={`/project/${projectRef}/database/settings`}>
  62. in the settings.
  63. </InlineLink>
  64. </p>
  65. </>
  66. }
  67. snippets={
  68. <>
  69. <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withApollo()} />
  70. <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withBriven()} />
  71. </>
  72. }
  73. />
  74. </div>
  75. )
  76. }
  77. const localSnippets = {
  78. withApollo: () => ({
  79. title: 'With Apollo GraphQL',
  80. bash: {
  81. language: 'js',
  82. code: `
  83. const { loading, error, data } = useQuery(gql\`
  84. query GetDogs {
  85. dogs {
  86. id
  87. breed
  88. owner {
  89. id
  90. name
  91. }
  92. }
  93. }
  94. \`)`,
  95. },
  96. js: {
  97. language: 'js',
  98. code: `
  99. const { loading, error, data } = useQuery(gql\`
  100. query GetDogs {
  101. dogs {
  102. id
  103. breed
  104. owner {
  105. id
  106. name
  107. }
  108. }
  109. }
  110. \`)`,
  111. },
  112. }),
  113. withBriven: () => ({
  114. title: 'With Briven',
  115. bash: {
  116. language: 'js',
  117. code: `
  118. const { data, error } = await briven
  119. .from('dogs')
  120. .select(\`
  121. id, breed,
  122. owner (id, name)
  123. \`)
  124. `,
  125. },
  126. js: {
  127. language: 'js',
  128. code: `
  129. const { data, error } = await briven
  130. .from('dogs')
  131. .select(\`
  132. id, breed,
  133. owner (id, name)
  134. \`)
  135. `,
  136. },
  137. }),
  138. }
  139. export default Introduction