OrvalOrval

Solid Query

Generate type-safe Solid Query primitives from OpenAPI

Generate fully typed TanStack Query for Solid primitives from your OpenAPI specification.

Configuration

Set the client option to solid-query:

orval.config.ts
import { defineConfig } from 'orval';

export default defineConfig({
  petstore: {
    output: {
      mode: 'tags-split',
      target: 'src/api/petstore.ts',
      schemas: 'src/api/model',
      client: 'solid-query',
      mock: true,
    },
    input: {
      target: './petstore.yaml',
    },
  },
});

Generated Output

Orval generates one primitive per path using @tanstack/solid-query. For example:

export const showPetById = (
  petId: string,
  options?: AxiosRequestConfig,
): Promise<AxiosResponse<Pet>> => {
  return axios.get(`/pets/${petId}`, options);
};

export const getShowPetByIdQueryKey = (petId: string) => [`/pets/${petId}`];

export const createShowPetById = <
  TData = Awaited<ReturnType<typeof showPetById>>,
  TError = Error,
>(
  petId: string,
  options?: {
    query?: CreateQueryOptions<
      Awaited<ReturnType<typeof showPetById>>,
      TError,
      TData
    >;
    axios?: AxiosRequestConfig;
  },
) => {
  const { query: queryOptions, axios: axiosOptions } = options ?? {};

  const queryKey = queryOptions?.queryKey ?? getShowPetByIdQueryKey(petId);
  const queryFn = () => showPetById(petId, axiosOptions);

  const query = createQuery<Awaited<ReturnType<typeof queryFn>>, TError, TData>(
    () => ({
      queryKey,
      queryFn,
      enabled: !!petId,
      ...queryOptions,
    }),
  );

  return {
    queryKey,
    ...query,
  };
};

Key Differences from React Query

Solid Query uses the create prefix instead of use:

  • createQuery instead of useQuery
  • createMutation instead of useMutation
  • createInfiniteQuery instead of useInfiniteQuery

The generated primitives follow SolidJS conventions and work seamlessly with Solid's reactivity system.

Infinite Queries

Generate infinite query primitives:

orval.config.ts
import { defineConfig } from 'orval';

export default defineConfig({
  petstore: {
    output: {
      client: 'solid-query',
      override: {
        query: {
          useQuery: true,
          useInfinite: true,
          useInfiniteQueryParam: 'nextId',
          options: {
            staleTime: 10000,
          },
        },
      },
    },
    input: {
      target: './petstore.yaml',
    },
  },
});

SolidStart vs Solid Query

If you're using SolidStart, consider using the SolidStart client instead, which uses native Solid Router primitives (query() and action()) for better SSR integration.

Set Query Data

When useSetQueryData: true is set, Orval generates type-safe helper functions to update cached query data:

export const setListPetsQueryData = (
  queryClient: QueryClient,
  params: ListPetsParams,
  updater:
    | Awaited<ReturnType<typeof listPets>>
    | undefined
    | ((
        old: Awaited<ReturnType<typeof listPets>> | undefined,
      ) => Awaited<ReturnType<typeof listPets>> | undefined),
) => {
  queryClient.setQueryData(getListPetsQueryKey(params), updater);
};

Full Example

See the complete Solid Query example on GitHub.

On this page