Skip to content

Commit 829028d

Browse files
authored
fix: make dprint optional dep (#920)
1 parent 1fb7e49 commit 829028d

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
2525
- [Why do I have to install `graphql`?](#why-do-i-have-to-install-graphql)
2626
- [Do I need to wrap my GraphQL documents inside the `gql` template exported by `graphql-request`?](#do-i-need-to-wrap-my-graphql-documents-inside-the-gql-template-exported-by-graphql-request)
2727
- [What sets `graphql-request` apart from other clients like Apollo, Relay, etc.?](#what-sets-graphql-request-apart-from-other-clients-like-apollo-relay-etc)
28+
- [Project Stats](#project-stats)
29+
- [Package Installs](#package-installs)
30+
- [Repo Beats](#repo-beats)
2831

2932
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3033

@@ -119,12 +122,6 @@ await client.request(document)
119122
- [Middleware](./examples/other-middleware.ts)
120123
- [Error Handling](./examples/other-error-handling.ts)
121124

122-
## Usage Trend
123-
124-
[Usage Trend of graphql-request](https://npm-compare.com/graphql-request/#timeRange=THREE_YEARS)
125-
126-
![image](https://github.com/jasonkuhrt/graphql-request/assets/3455798/8d27c215-f20f-46f9-b38d-61f41d14882f)
127-
128125
## Node Version Support
129126

130127
We only (officially) support [versions of Nodejs](https://github.com/nodejs/Release#release-schedule) of the following status:
@@ -203,3 +200,15 @@ No. It is there for convenience so that you can get the tooling support like aut
203200
`graphql-request` is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.
204201

205202
Compared to GraphQL clients like Apollo or Relay, `graphql-request` doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.
203+
204+
## Project Stats
205+
206+
### Package Installs
207+
208+
<a href="https://npm-compare.com/graphql-request#timeRange=FIVE_YEARS" target="_blank">
209+
<img src="https://npm-compare.com/img/npm-trend/FIVE_YEARS/graphql-request.png" width="100%" alt="NPM Usage Trend of graphql-request" />
210+
</a>
211+
212+
### Repo Beats
213+
214+
![Alt](https://repobeats.axiom.co/api/embed/aeb7beaee43b190e90868357c5a2898f517fb63e.svg "Repobeats analytics image")

package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,26 @@
8080
"release:pr": "dripip pr"
8181
},
8282
"dependencies": {
83-
"@dprint/formatter": "^0.3.0",
84-
"@dprint/typescript": "^0.91.1",
8583
"@graphql-typed-document-node/core": "^3.2.0",
8684
"@molt/command": "^0.9.0",
87-
"dprint": "^0.46.2",
8885
"zod": "^3.23.8"
8986
},
9087
"peerDependencies": {
91-
"graphql": "14 - 16"
88+
"graphql": "14 - 16",
89+
"dprint": "^0.46.2",
90+
"@dprint/formatter": "^0.3.0",
91+
"@dprint/typescript": "^0.91.1"
92+
},
93+
"peerDependenciesMeta": {
94+
"dprint": {
95+
"optional": true
96+
},
97+
"@dprint/formatter": {
98+
"optional": true
99+
},
100+
"@dprint/typescript": {
101+
"optional": true
102+
}
92103
},
93104
"devDependencies": {
94105
"@arethetypeswrong/cli": "^0.15.3",

src/layers/2_generator/files.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createFromBuffer } from '@dprint/formatter'
2-
import { getPath } from '@dprint/typescript'
1+
import type { Formatter } from '@dprint/formatter'
32
import _ from 'json-bigint'
43
import fs from 'node:fs/promises'
54
import * as Path from 'node:path'
@@ -18,6 +17,16 @@ export interface Input {
1817
errorTypeNamePattern?: OptionsInput['errorTypeNamePattern']
1918
}
2019

20+
const getTypeScriptFormatter = async (): Promise<Formatter | undefined> => {
21+
try {
22+
const { createFromBuffer } = await import(`@dprint/formatter`)
23+
const { getPath } = await import(`@dprint/typescript`)
24+
return createFromBuffer(await fs.readFile(getPath()))
25+
} catch (error) {
26+
return undefined
27+
}
28+
}
29+
2130
export const generateFiles = async (input: Input) => {
2231
const sourceDirPath = input.sourceDirPath ?? process.cwd()
2332
const schemaPath = input.schemaPath ?? Path.join(sourceDirPath, `schema.graphql`)
@@ -31,7 +40,7 @@ export const generateFiles = async (input: Input) => {
3140
customScalarCodecsFilePath.replace(/\.ts$/, `.js`),
3241
)
3342
const customScalarCodecsPathExists = await fileExists(customScalarCodecsFilePath)
34-
const typeScriptFormatter = (input.format ?? true) ? createFromBuffer(await fs.readFile(getPath())) : undefined
43+
const typeScriptFormatter = (input.format ?? true) ? await getTypeScriptFormatter() : undefined
3544

3645
const codes = generateCode({
3746
name: input.name,

0 commit comments

Comments
 (0)