-
Good afternoon, I am trying since this morning to get the return type of the query to be share to the data member of the OperationResultStore. I tried to apply what is shown inside the documentation and i get some result: /* eslint-disable */
import * as types from './graphql';
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
/**
* Map of all GraphQL operations in the project.
*
* This map has several performance disadvantages:
* 1. It is not tree-shakeable, so it will include all operations in the project.
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
* 3. It does not support dead code elimination, so it will add unused operations.
*
* Therefore it is highly recommended to use the babel or swc plugin for production.
*/
const documents = {
"query checkPasswordResetToken($token: String!) {\n checkPasswordResetToken(token: $token)\n}": types.CheckPasswordResetTokenDocument,
};
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*
*
* @example
* ```ts
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
* ```
*
* The query argument is unknown!
* Please regenerate the types.
*/
export function graphql(source: string): unknown;
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query checkPasswordResetToken($token: String!) {\n checkPasswordResetToken(token: $token)\n}"): (typeof documents)["query checkPasswordResetToken($token: String!) {\n checkPasswordResetToken(token: $token)\n}"];
export function graphql(source: string) {
return (documents as any)[source] ?? {};
}
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never; Then the svelte page: import { getContextClient, gql, queryStore } from "@urql/svelte";
import type { PageData } from "./$types";
import { graphql } from "$gql";
export let data: PageData;
const token = data.props.token;
let tokenValidity = queryStore({
client: getContextClient(),
query: graphql("query checkPasswordResetToken($token: String!) {\n checkPasswordResetToken(token: $token)\n}"),
variables: { token }
})
$: if( $tokenValidity.data ) {
const isValid = $tokenValidity.data.checkPasswordResetToken; // TS Error or data is defined as any so no autocompletion available
if ( !isValid ) {
// goto("/auth/login");
// Add a notification to the user that the token is invalid
}
} But I don't why the data type always got an any type. Am doing something wrong there ? data : {
checkPasswordResetToken: boolean
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok seems like I find the problem to this, it is not originating from this package but from the |
Beta Was this translation helpful? Give feedback.
Ok seems like I find the problem to this, it is not originating from this package but from the
@graphql-typed-document-node/core
. I do not know why, but it seems they change something from v3.1.1 to 3.2.0, and vite does not like it. Now I do have the TS which is correctly generated.