Skip to content

graphql-ts

Simple Type-Safe GraphQL Schemas in TypeScript

const
const Query: GObjectType<unknown, Context>
Query
=
const g: GWithContext<Context>
g
.
object: <unknown>(youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction?: {
youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction: true;
}) => <Fields, Interfaces>(config: {
...;
} & Omit<...>) => GObjectType<...>
object
()({
name: string
name
: "Query",
fields: {
user: GField<unknown, {
id: GArg<GNonNull<GScalarType<string, string>>, false>;
}, GObjectType<UserSource, Context>, unknown, Context>;
} | (() => {
user: GField<unknown, {
id: GArg<GNonNull<GScalarType<string, string>>, false>;
}, GObjectType<UserSource, Context>, unknown, Context>;
})
fields
: {
user: GField<unknown, {
id: GArg<GNonNull<GScalarType<string, string>>, false>;
}, GObjectType<UserSource, Context>, unknown, Context>
user
:
const g: GWithContext<Context>
g
.
field: <unknown, GObjectType<UserSource, Context>, (_: unknown, args: {
readonly id: string;
}, context: Context) => Promise<UserSource | null>, {
...;
}>(field: FieldFuncArgs<...> & {
...;
}) => GField<...>
field
({
type: GObjectType<UserSource, Context>
type
:
const User: GObjectType<UserSource, Context>
User
,
args?: {
id: GArg<GNonNull<GScalarType<string, string>>, false>;
}
args
: {
id: GArg<GNonNull<GScalarType<string, string>>, false>
id
:
const g: GWithContext<Context>
g
.
arg: <GNonNull<GScalarType<string, string>>, undefined>(arg: {
type: GNonNull<GScalarType<string, string>>;
description?: Maybe<string>;
extensions?: (Readonly<...> & Readonly<...>) | ... 1 more ... | undefined;
astNode?: Maybe<...>;
deprecationReason?: Maybe<...>;
} & {
...;
}) => GArg<...>
arg
({
type: GNonNull<GScalarType<string, string>>
type
:
const g: GWithContext<Context>
g
.
nonNull: <GScalarType<string, string>>(of: GScalarType<string, string>) => GNonNull<GScalarType<string, string>>
nonNull
(
const g: GWithContext<Context>
g
.
type ID: GScalarType<string, string>
ID
) }),
},
resolve: ((source: unknown, args: {
readonly id: string;
}, context: Context, info: GraphQLResolveInfo) => InferValueFromOutputType<GObjectType<UserSource, Context>>) & ((_: unknown, args: {
...;
}, context: Context) => Promise<...>)
resolve
(
_: unknown
_
,
args: {
readonly id: string;
}
args
,
context: Context
context
) {
return
context: Context
context
.
loadUser: (id: string) => Promise<UserSource | null>
loadUser
(
args: {
readonly id: string;
}
args
. );
id
},
}),
},
});

Type Safety

@graphql-ts/schema provides type safety when defining your GraphQL schema while avoiding the need for code generation, decorators, or other complexity.

Direct Compatibility with GraphQL.js

Use @graphql-ts/schema with any existing GraphQL server that uses GraphQL.js, like GraphQL Yoga, Apollo Server, graphql-http, etc.