mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem `@graphql-codegen/cli` and related packages in `apps/studio` and `apps/docs` were pinned to old major versions (`cli` 5.0.5, `typescript` 4.1.6, `typescript-resolvers` 4.5.0). ## Solution - Bump `@graphql-codegen/cli` to `^7.0.0` and `@graphql-codegen/typescript-resolvers` to `^6.0.0`. Drop the explicit `@graphql-codegen/typescript` dependency from `apps/docs`. - Regenerate the Studio GraphQL output in `apps/studio/data/graphql/` with the new codegen. The generated files now include an `index.ts` export change, and `graphql.ts` is much smaller. - Refresh `apps/studio/scripts/schema.graphql`, which picks up the new `ManagementApiReference` search result type. - Update `.prettierignore` (ignore `apps/studio/.output`, `apps/studio/dist`, and all of `apps/ui-library/public`) and run Prettier on the regenerated files. ## Review instructions 1. Check the dependency bumps in `apps/studio/package.json` and `apps/docs/package.json`. 2. Re-run the Studio codegen and confirm it produces no diff in `apps/studio/data/graphql/`. 3. Run `pnpm typecheck` and confirm the GraphQL consumers in Studio still compile. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
86 lines
3.7 KiB
TypeScript
86 lines
3.7 KiB
TypeScript
/* eslint-disable */
|
|
import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'
|
|
|
|
import { Incremental, TypedDocumentString } from './graphql'
|
|
|
|
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
|
|
TDocumentType extends DocumentTypeDecoration<infer TType, any>
|
|
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
|
|
? TKey extends string
|
|
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
|
|
: never
|
|
: never
|
|
: never
|
|
|
|
// return non-nullable if `fragmentType` is non-nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
|
|
): TType
|
|
// return nullable if `fragmentType` is undefined
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
|
|
): TType | undefined
|
|
// return nullable if `fragmentType` is nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
|
|
): TType | null
|
|
// return nullable if `fragmentType` is nullable or undefined
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
|
|
): TType | null | undefined
|
|
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
): Array<TType>
|
|
// return array of nullable if `fragmentType` is array of nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
): Array<TType> | null | undefined
|
|
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
): ReadonlyArray<TType>
|
|
// return readonly array of nullable if `fragmentType` is array of nullable
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
): ReadonlyArray<TType> | null | undefined
|
|
export function useFragment<TType>(
|
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
fragmentType:
|
|
| FragmentType<DocumentTypeDecoration<TType, any>>
|
|
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
| null
|
|
| undefined
|
|
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
|
|
return fragmentType as any
|
|
}
|
|
|
|
export function makeFragmentData<
|
|
F extends DocumentTypeDecoration<any, any>,
|
|
FT extends ResultOf<F>,
|
|
>(data: FT, _fragment: F): FragmentType<F> {
|
|
return data as FragmentType<F>
|
|
}
|
|
export function isFragmentReady<TQuery, TFrag>(
|
|
queryNode: TypedDocumentString<TQuery, any>,
|
|
fragmentNode: TypedDocumentString<TFrag, any>,
|
|
data: FragmentType<TypedDocumentString<Incremental<TFrag>, any>> | null | undefined
|
|
): data is FragmentType<typeof fragmentNode> {
|
|
const deferredFields = queryNode.__meta__?.deferredFields as Record<string, (keyof TFrag)[]>
|
|
const fragName = fragmentNode.__meta__?.fragmentName as string | undefined
|
|
|
|
if (!deferredFields || !fragName) return true
|
|
|
|
const fields = deferredFields[fragName] ?? []
|
|
return fields.length > 0 && fields.every((field) => data && field in data)
|
|
}
|