Files
supabase/apps/docs/resources/rootSchema.ts
T
Charis aba0095bd7 feat(content api): add error endpoint (#35941)
* feat(content api): add error endpoint

Add an endpoint to return the details of a Supabase error, given the
error code and service.

Schema additions:

```graphql
type RootQueryType {
  "...previous root queries"

  """Get the details of an error code returned from a Supabase service"""
  error(code: String!, service: Service!): Error
}

"""An error returned by a Supabase service"""
type Error {
  """
  The unique code identifying the error. The code is stable, and can be used for string matching during error handling.
  """
  code: String!

  """The Supabase service that returns this error."""
  service: Service!

  """The HTTP status code returned with this error."""
  httpStatusCode: Int

  """
  A human-readable message describing the error. The message is not stable, and should not be used for string matching during error handling. Use the code instead.
  """
  message: String
}

enum Service {
  AUTH
  REALTIME
  STORAGE
}
```

* test(content api): add tests for top-level query `error`
2025-05-29 15:39:47 -04:00

49 lines
1.4 KiB
TypeScript

import {
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
printSchema,
} from 'graphql'
import { RootQueryTypeResolvers } from '~/__generated__/graphql'
import { errorRoot } from './error/errorResolver'
import { searchRoot } from './globalSearch/globalSearchResolver'
import { GraphQLObjectTypeGuide } from './guide/guideSchema'
import { GraphQLObjectTypeReferenceCLICommand } from './reference/referenceCLISchema'
import { GraphQLObjectTypeReferenceSDKFunction } from './reference/referenceSDKSchema'
import { GraphQLObjectTypeTroubleshooting } from './troubleshooting/troubleshootingSchema'
const GRAPHQL_FIELD_INTROSPECT = 'schema' as const
type IntrospectResolver = RootQueryTypeResolvers[typeof GRAPHQL_FIELD_INTROSPECT]
const resolveIntrospect: IntrospectResolver = async () => {
const schema = printSchema(rootGraphQLSchema)
return schema
}
const introspectRoot = {
[GRAPHQL_FIELD_INTROSPECT]: {
description: 'Get the GraphQL schema for this endpoint',
type: new GraphQLNonNull(GraphQLString),
resolve: resolveIntrospect,
},
}
export const rootGraphQLSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
...introspectRoot,
...searchRoot,
...errorRoot,
},
}),
types: [
GraphQLObjectTypeGuide,
GraphQLObjectTypeReferenceCLICommand,
GraphQLObjectTypeReferenceSDKFunction,
GraphQLObjectTypeTroubleshooting,
],
})