Skip to content

Commit 43e05dd

Browse files
refactor: simplify GraphQL client error handling and remove unused import
1 parent e9001b2 commit 43e05dd

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

playground-nuxt/app/graphql/ofetch.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// This file is auto-generated once by nitro-graphql for quick start
22
// You can modify this file according to your needs
3-
import type { ExecutionResult } from 'graphql'
43
import type { Requester } from './sdk'
54
import { getSdk } from './sdk'
65

@@ -15,11 +14,9 @@ export function createGraphQLClient(endpoint: string): Requester {
1514
'Content-Type': 'application/json',
1615
...headers,
1716
},
18-
}) as ExecutionResult
17+
})
1918

20-
return result.errors?.length
21-
? Promise.reject(new Error(result.errors[0]?.message || 'GraphQL error'))
22-
: result.data as R
19+
return result as R
2320
}
2421
}
2522

src/utils/type-generation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function generateNuxtOfetchClient(clientDir: string) {
1717
if (!existsSync(ofetchPath)) {
1818
const ofetchContent = `// This file is auto-generated once by nitro-graphql for quick start
1919
// You can modify this file according to your needs
20-
import type { ExecutionResult } from 'graphql'
2120
import type { Requester } from './sdk'
2221
import { getSdk } from './sdk'
2322
@@ -32,11 +31,9 @@ export function createGraphQLClient(endpoint: string): Requester {
3231
'Content-Type': 'application/json',
3332
...headers,
3433
},
35-
}) as ExecutionResult
34+
})
3635
37-
return result.errors?.length
38-
? Promise.reject(new Error(result.errors[0]?.message || 'GraphQL error'))
39-
: result.data as R
36+
return result as R
4037
}
4138
}
4239

0 commit comments

Comments
 (0)