mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Add a top-level field to search docs globally. Right now this only
returns Markdown guides (not references, GitHub discussions, or partner
pages.
The full GraphQL schema at this point:
```
schema {
query: RootQueryType
}
type RootQueryType {
"""Get the GraphQL schema for this endpoint"""
schema: String!
"""Search the Supabase docs for content matching a query string"""
searchDocs(query: String!, limit: Int): SearchResultCollection
}
"""A collection of search results containing content from Supabase docs"""
type SearchResultCollection {
"""A list of edges containing nodes in this collection"""
edges: [SearchResultEdge!]!
"""The nodes in this collection, directly accessible"""
nodes: [SearchResult!]!
"""The total count of items available in this collection"""
totalCount: Int!
}
"""An edge in a collection of SearchResults"""
type SearchResultEdge {
"""The SearchResult at the end of the edge"""
node: SearchResult!
}
"""Document that matches a search query"""
interface SearchResult {
"""The title of the matching result"""
title: String
"""The URL of the matching result"""
href: String
"""The full content of the matching result"""
content: String
}
```
Towards DOCS-214
39 lines
995 B
TypeScript
39 lines
995 B
TypeScript
import {
|
|
GraphQLNonNull,
|
|
GraphQLObjectType,
|
|
GraphQLSchema,
|
|
GraphQLString,
|
|
printSchema,
|
|
} from 'graphql'
|
|
import { RootQueryTypeResolvers } from '~/__generated__/graphql'
|
|
import { searchRoot } from './globalSearch/globalSearchResolver'
|
|
import { GraphQLObjectTypeGuide } from './guide/guideSchema'
|
|
|
|
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,
|
|
},
|
|
}),
|
|
types: [GraphQLObjectTypeGuide],
|
|
})
|