Skip to content

Commit

Permalink
feat: add TS type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Mar 4, 2024
1 parent d4279f4 commit 8b426b3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/getSchemaTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type RawField = {
name: string
type: RawType
}
export type RawType = {
name: string | null | undefined
kind: string
ofType?: RawType | null | undefined
fields?: Array<RawField> | null | undefined
}
export type Field = {
name: string
type: Type
parent: Type
}
export type Type = {
name: string | null | undefined
kind: string
ofType?: Type | null | undefined
fields?:
| {
[name: string]: Field
}
| null
| undefined
parents?: Array<Field>
}
export type Types = {
[name: string]: Type
}
20 changes: 20 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ApolloClient } from 'apollo-client'
import type { Types } from './getSchemaTypes'
import typesQuery, { TypeMetadata } from './typesQuery'
export { typesQuery }
export type { TypeMetadata }

type Term = [string, any, string | null | undefined] | [string, any] | [string]

declare const refetch: {
(
client: unknown,
typenameOrTerms: string | ReadonlyArray<Term>,
predicate?: any | null,
idField?: string
): Promise<any>
fetchTypeMetadata(client: ApolloClient<any>): Promise<Types>
setTypeMetadata(metadata: Promise<TypeMetadata> | TypeMetadata): void
}

export default refetch
46 changes: 46 additions & 0 deletions src/typesQuery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { DocumentNode } from 'graphql'
declare const typesQuery: DocumentNode
export default typesQuery

type __TypeKind =
| 'SCALAR'
| 'OBJECT'
| 'INTERFACE'
| 'UNION'
| 'ENUM'
| 'INPUT_OBJECT'
| 'LIST'
| 'NON_NULL'

export type TypeMetadata = {
data: {
__schema: {
types: Array<{
name: string | null | undefined
fields: Array<{
name: string
type:
| {
name: string | null | undefined
kind: __TypeKind
ofType:
| {
name: string | null | undefined
kind: __TypeKind
ofType:
| {
name: string | null | undefined
}
| null
| undefined
}
| null
| undefined
}
| null
| undefined
}>
}>
}
}
}

0 comments on commit 8b426b3

Please sign in to comment.