Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export type ActiveDailyCodingChallengeQuestion = z.infer<
>;

export async function fetchActiveDailyCodingChallengeQuestionWithoutDateValidation(): Promise<ActiveDailyCodingChallengeQuestion> {
// TODO: have a way to omit variables when there aren't any
const { activeDailyCodingChallengeQuestion } = await fetchGraphQL({});
const { activeDailyCodingChallengeQuestion } = await fetchGraphQL();

return activeDailyCodingChallengeQuestionZodType.parse(
activeDailyCodingChallengeQuestion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import invariant from "invariant";
import nullthrows from "nullthrows";
import { z } from "zod";

import { isObject } from "@code-chronicles/util/isObject";
import { only } from "@code-chronicles/util/only";
import { spliceString } from "@code-chronicles/util/spliceString";

Expand All @@ -28,12 +27,13 @@ export const plugin: PluginFunction<{}> = async function plugin(
const { document, rawSDL: unminifiedGraphQL, location } = only(documents);
const definition = only(nullthrows(document).definitions);
invariant(
isObject(definition) &&
definition.kind === "OperationDefinition" &&
definition.kind === "OperationDefinition" &&
definition.operation === "query",
"Expected a query!",
);

const hasVariables = (definition?.variableDefinitions ?? []).length > 0;

// TODO: should we call it a Zod schema instead?

// Generate a Zod type to parse the result!
Expand Down Expand Up @@ -86,8 +86,8 @@ export const plugin: PluginFunction<{}> = async function plugin(
export type QueryResult = z.infer<typeof queryResultZodType>;
export type QueryVariables = OriginalQueryVariables;

export async function fetchGraphQL(variables: QueryVariables): Promise<QueryResult> {
const untrustedData = await getGraphQLClient().request(QUERY, variables);
export async function fetchGraphQL(${hasVariables ? "variables: QueryVariables" : ""}): Promise<QueryResult> {
const untrustedData = await getGraphQLClient().request(QUERY${hasVariables ? ", variables" : ""});

// The type annotation serves as a TypeScript assert that the generated
// Zod type is compatible with the types generated by GraphQL Codegen.
Expand Down
Loading