Resolver function: (ctx, data) => result.
ctx is Context (or AuthorizedContext when authorized: true) with userId.data is the typed GraphQL input (or void if no input).Configuration for the query/mutation.
The GraphQL return type (type-graphql @ObjectType class, String, Boolean, Number, etc.).
Optional GraphQL input type (@InputType class or scalar) for the input argument.
Optional. Set { nullable: true } to allow null returns.
Optional. Set { nullable: true } to allow null input.
If true, the resolver requires an authenticated user. ctx is typed as AuthorizedContext (non-null userId).
If true, registers as a @Mutation; otherwise registers as a @Query.
A QueryDefinition with .call(data) and .authCall(data) for server-side invocation.
import { query } from "naystack/graphql";
export default query(
async (ctx) => {
if (!ctx.userId) return null;
const [user] = await db.select().from(UserTable).where(eq(UserTable.id, ctx.userId));
return user || null;
},
{ output: User, outputOptions: { nullable: true } },
);
export default query(
async (ctx, input: SubmitFeedbackInput) => {
await db.insert(FeedbackTable).values({ userId: ctx.userId, score: input.score, text: input.text });
return true;
},
{ output: Boolean, input: SubmitFeedbackInput, authorized: true, mutation: true },
);
Defines a type-graphql query or mutation with typed input/output and optional auth. Use with QueryLibrary to build resolver classes for
initGraphQLServer.Each query definition gets
.call(data)and.authCall(data)methods for direct server-side invocation (e.g. in Server Components or other resolvers). Both are cached via React'scache().