|
5 | 5 | /* prettier-ignore */ |
6 | 6 | import type * as Types from '#graphql/client'; |
7 | 7 |
|
8 | | -import type { DocumentNode, ExecutionResult } from 'graphql'; |
9 | | -import gql from 'graphql-tag'; |
| 8 | +import type { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; |
| 9 | +import type { ExecutionResult } from 'graphql'; |
| 10 | +export class TypedDocumentString<TResult, TVariables> |
| 11 | + extends String |
| 12 | + implements DocumentTypeDecoration<TResult, TVariables> |
| 13 | +{ |
| 14 | + __apiType?: NonNullable<DocumentTypeDecoration<TResult, TVariables>['__apiType']>; |
| 15 | + private value: string; |
| 16 | + public __meta__?: Record<string, any> | undefined; |
10 | 17 |
|
11 | | -export const HelloDocument = /*#__PURE__*/ gql` |
| 18 | + constructor(value: string, __meta__?: Record<string, any> | undefined) { |
| 19 | + super(value); |
| 20 | + this.value = value; |
| 21 | + this.__meta__ = __meta__; |
| 22 | + } |
| 23 | + |
| 24 | + override toString(): string & DocumentTypeDecoration<TResult, TVariables> { |
| 25 | + return this.value; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +export const HelloDocument = /*#__PURE__*/ new TypedDocumentString(` |
| 30 | + query Hello { |
| 31 | + helloCI |
| 32 | +} |
| 33 | + `) as unknown as TypedDocumentString<Types.HelloQuery, Types.HelloQueryVariables>; |
| 34 | +export const GetUsersDocument = /*#__PURE__*/ new TypedDocumentString(` |
| 35 | + query GetUsers { |
| 36 | + users { |
| 37 | + id |
| 38 | + name |
| 39 | + } |
| 40 | +} |
| 41 | + `) as unknown as TypedDocumentString<Types.GetUsersQuery, Types.GetUsersQueryVariables>; |
| 42 | +export const GetGreetingDocument = /*#__PURE__*/ new TypedDocumentString(` |
| 43 | + query GetGreeting { |
| 44 | + greeting(name: "World") |
| 45 | +} |
| 46 | + `) as unknown as TypedDocumentString<Types.GetGreetingQuery, Types.GetGreetingQueryVariables>; |
| 47 | + |
| 48 | +export const HelloDocument = /*#__PURE__*/ new TypedDocumentString(` |
12 | 49 | query Hello { |
13 | 50 | helloCI |
14 | 51 | } |
15 | | - `; |
16 | | -export const GetUsersDocument = /*#__PURE__*/ gql` |
| 52 | + `); |
| 53 | +export const GetUsersDocument = /*#__PURE__*/ new TypedDocumentString(` |
17 | 54 | query GetUsers { |
18 | 55 | users { |
19 | 56 | id |
20 | 57 | name |
21 | 58 | } |
22 | 59 | } |
23 | | - `; |
24 | | -export const GetGreetingDocument = /*#__PURE__*/ gql` |
| 60 | + `); |
| 61 | +export const GetGreetingDocument = /*#__PURE__*/ new TypedDocumentString(` |
25 | 62 | query GetGreeting { |
26 | 63 | greeting(name: "World") |
27 | 64 | } |
28 | | - `; |
29 | | -export type Requester<C = {}, E = unknown> = <R, V>(doc: DocumentNode, vars?: V, options?: C) => Promise<ExecutionResult<R, E>> | AsyncIterable<ExecutionResult<R, E>> |
| 65 | + `); |
| 66 | +export type Requester<C = {}, E = unknown> = <R, V>(doc: string, vars?: V, options?: C) => Promise<ExecutionResult<R, E>> | AsyncIterable<ExecutionResult<R, E>> |
30 | 67 | export function getSdk<C, E>(requester: Requester<C, E>) { |
31 | 68 | return { |
32 | 69 | Hello(variables?: Types.HelloQueryVariables, options?: C): Promise<ExecutionResult<Types.HelloQuery, E>> { |
|
0 commit comments