The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
adds graphiql menu item
Alaister Young6cfb9283d662
diff --git a/package-lock.json b/package-lock.jsonindex c676116c2ca..2d9b2c00154 100644--- a/package-lock.json+++ b/package-lock.json@@ -37120,6 +37120,7 @@"studio": {"version": "0.0.9","dependencies": {+ "@graphiql/toolkit": "^0.8.0","@headlessui/react": "^1.4.1","@monaco-editor/react": "^4.3.1","@next/bundle-analyzer": "^12.0.4",@@ -62070,6 +62071,7 @@"version": "file:studio","requires": {"@babel/core": "^7.17.5",+ "@graphiql/toolkit": "*","@headlessui/react": "^1.4.1","@monaco-editor/react": "^4.3.1","@next/bundle-analyzer": "^12.0.4",@@ -62126,8 +62128,8 @@"dayjs": "^1.11.0","file-saver": "^2.0.5","generate-password": "^1.7.0",- "graphiql": "*",- "graphql": "*",+ "graphiql": "^2.0.13",+ "graphql": "^16.6.0","html-to-image": "^1.10.8","immutability-helper": "^3.1.1","jest": "^27.4.0",diff --git a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsxindex c5b6ddb9036..6ef0458c2be 100644--- a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx+++ b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx@@ -50,6 +50,20 @@ export const generateToolRoutes = (ref?: string, project?: ProjectBase): Route[]ref &&(isProjectPaused ? homeUrl : isProjectBuilding ? buildingUrl : `/project/${ref}/sql`),},+ {+ key: 'graphiql',+ label: 'GraphiQL',+ icon: (+ <SVG+ src="/img/graphql.svg"+ style={{ width: `${18}px`, height: `${18}px` }}+ preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}+ />+ ),+ link:+ ref &&+ (isProjectPaused ? homeUrl : isProjectBuilding ? buildingUrl : `/project/${ref}/graphiql`),+ },]}export const generateProductRoutes = (ref?: string, project?: ProjectBase): Route[] => {diff --git a/studio/package.json b/studio/package.jsonindex 03b6da52c66..62bd3fbd52a 100644--- a/studio/package.json+++ b/studio/package.json@@ -14,6 +14,7 @@"prettier:write": "prettier --write ."},"dependencies": {+ "@graphiql/toolkit": "^0.8.0","@headlessui/react": "^1.4.1","@monaco-editor/react": "^4.3.1","@next/bundle-analyzer": "^12.0.4",diff --git a/studio/pages/project/[ref]/graphiql/index.tsx b/studio/pages/project/[ref]/graphiql/index.tsxnew file mode 100644index 00000000000..bbf6f911558--- /dev/null+++ b/studio/pages/project/[ref]/graphiql/index.tsx@@ -0,0 +1,59 @@+import { createGraphiQLFetcher } from '@graphiql/toolkit'+import { GraphiQL } from 'graphiql'+import 'graphiql/graphiql.css'++import { ProjectLayoutWithAuth } from 'components/layouts'+import Connecting from 'components/ui/Loading/Loading'+import { useParams, useProjectSettings } from 'hooks'+import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants'+import { useMemo } from 'react'+import { NextPageWithLayout } from 'types'+import { IconAlertCircle } from 'ui'++const GraphiQLPage: NextPageWithLayout = () => {+ const { ref } = useParams()++ const {+ services,+ isError: isProjectSettingsError,+ isLoading: isProjectSettingsLoading,+ } = useProjectSettings(ref)++ const apiService = (services ?? []).find((x: any) => x.app.id == DEFAULT_PROJECT_API_SERVICE_ID)+ const apiConfig = apiService?.app_config ?? {}+ const apiKeys = apiService?.service_api_keys ?? []++ const graphqlUrl = `https://${apiConfig.endpoint}/graphql/v1`+ const anonKey = apiKeys.find((key: any) => key.tags === 'anon')?.api_key++ const fetcher = useMemo(() => {+ return createGraphiQLFetcher({+ url: graphqlUrl,+ fetch,+ headers: {+ apikey: anonKey,+ },+ })+ }, [graphqlUrl, anonKey])++ if (isProjectSettingsLoading) {+ return <Connecting />+ }++ if (isProjectSettingsError) {+ return (+ <div className="py-8 flex items-center justify-center space-x-2">+ <IconAlertCircle size={16} strokeWidth={1.5} />+ <p className="text-sm text-scale-1100">Failed to retrieve API keys</p>+ </div>+ )+ }++ return <GraphiQL fetcher={fetcher} />+}++GraphiQLPage.getLayout = (page) => (+ <ProjectLayoutWithAuth title="GraphiQL">{page}</ProjectLayoutWithAuth>+)++export default GraphiQLPagediff --git a/studio/pages/project/[ref]/graphql/index.tsx b/studio/pages/project/[ref]/graphql/index.tsxdeleted file mode 100644index 01b89f9585e..00000000000--- a/studio/pages/project/[ref]/graphql/index.tsx+++ /dev/null@@ -1,34 +0,0 @@-import { createGraphiQLFetcher } from '@graphiql/toolkit'-import { GraphiQL } from 'graphiql'-import { observer } from 'mobx-react-lite'-import 'graphiql/graphiql.css'--import { ProjectLayoutWithAuth } from 'components/layouts'-import { useStore } from 'hooks'-import { NextPageWithLayout } from 'types'--const fetcher = createGraphiQLFetcher({- url: 'https://yrjyofbjvjypdsexuvvu.supabase.red/graphql/v1',- fetch,- headers: {- apikey:- 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlyanlvZmJqdmp5cGRzZXh1dnZ1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjczNTg0OTIsImV4cCI6MTk4MjkzNDQ5Mn0.CMVzrM7R0ym8ukt5miDoNL0ELhsM9fxOx2Qpm0hsLFE',- },-})--const GraphiQLPage: NextPageWithLayout = () => {- const { ui } = useStore()-- const project = ui.selectedProject- console.log('project:', project)-- return <GraphiQL fetcher={fetcher} />-}--GraphiQLPage.getLayout = (page) => (- <ProjectLayoutWithAuth>- <main className="flex-1">{page}</main>- </ProjectLayoutWithAuth>-)--export default observer(GraphiQLPage)diff --git a/studio/public/img/graphql.svg b/studio/public/img/graphql.svgnew file mode 100644index 00000000000..8060db470ea--- /dev/null+++ b/studio/public/img/graphql.svg@@ -0,0 +1,10 @@+<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 400 400">+ <path fill="currentColor" d="m57.468 302.66-14.376-8.3 160.15-277.38 14.376 8.3z"/>+ <path fill="currentColor" d="M39.8 272.2h320.3v16.6H39.8z"/>+ <path fill="currentColor" d="m206.348 374.026-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z"/>+ <path fill="currentColor" d="m54.482 132.883-8.3-14.375 160.21-92.5 8.3 14.375z"/>+ <path fill="currentColor" d="m342.568 302.663-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5z"/>+ <path fill="currentColor" d="M330.9 107.5h16.6v185h-16.6z"/>+ <path fill="currentColor" d="m203.522 367-7.25-12.558 139.34-80.45 7.25 12.557z"/>+ <path fill="currentColor" d="M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9"/>+</svg>\ No newline at end of file