mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Ensure that resolvers are properly typed by adding a script to generate types from the root schema.
35 lines
813 B
TypeScript
35 lines
813 B
TypeScript
import {
|
|
GraphQLNonNull,
|
|
GraphQLObjectType,
|
|
GraphQLSchema,
|
|
GraphQLString,
|
|
printSchema,
|
|
} from 'graphql'
|
|
import { RootQueryTypeResolvers } from '~/__generated__/graphql'
|
|
|
|
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,
|
|
},
|
|
}),
|
|
})
|