Skip to content

Commit

Permalink
Urql 4 now have more strict types for variables (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesin authored Sep 7, 2023
1 parent b2ab7cb commit e330c6e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-pens-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-vue-urql': minor
---

Generate explicit type for variables used in a query to work with urql v4
4 changes: 2 additions & 2 deletions packages/plugins/typescript/vue-urql/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export function use${operationName}<R = ${operationResultType}>(options: Omit<Ur
}

return `
export function use${operationName}(options: Omit<Urql.Use${operationType}Args<never, ${operationVariablesTypes}>, 'query'> = {}) {
return Urql.use${operationType}<${operationResultType}>({ query: ${documentVariableName}, ...options });
export function use${operationName}(options: Omit<Urql.Use${operationType}Args<never, ${operationVariablesTypes}>, 'query'>) {
return Urql.use${operationType}<${operationResultType}, ${operationVariablesTypes}>({ query: ${documentVariableName}, ...options });
};`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as Urql from '@urql/vue';
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export function useTestQuery(options: Omit<Urql.UseQueryArgs<never, Operations.TestQueryVariables>, 'query'> = {}) {
return Urql.useQuery<Operations.TestQuery>({ query: Operations.TestDocument, ...options });
export function useTestQuery(options: Omit<Urql.UseQueryArgs<never, Operations.TestQueryVariables>, 'query'>) {
return Urql.useQuery<Operations.TestQuery, Operations.TestQueryVariables>({ query: Operations.TestDocument, ...options });
};"
`;
4 changes: 2 additions & 2 deletions packages/plugins/typescript/vue-urql/tests/urql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ query MyFeed {
)) as Types.ComplexPluginOutput;

expect(content.content).toBeSimilarStringTo(`
export function useFeedQuery(options: Omit<Urql.UseQueryArgs<never, FeedQueryVariables>, 'query'> = {}) {
return Urql.useQuery<FeedQuery>({ query: FeedDocument, ...options });
export function useFeedQuery(options: Omit<Urql.UseQueryArgs<never, FeedQueryVariables>, 'query'>) {
return Urql.useQuery<FeedQuery, FeedQueryVariables>({ query: FeedDocument, ...options });
};`);

expect(content.content).toBeSimilarStringTo(`
Expand Down

0 comments on commit e330c6e

Please sign in to comment.