Skip to content

Commit

Permalink
fix: make dprint optional dep (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Jun 11, 2024
1 parent 1fb7e49 commit 829028d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
- [Why do I have to install `graphql`?](#why-do-i-have-to-install-graphql)
- [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)
- [What sets `graphql-request` apart from other clients like Apollo, Relay, etc.?](#what-sets-graphql-request-apart-from-other-clients-like-apollo-relay-etc)
- [Project Stats](#project-stats)
- [Package Installs](#package-installs)
- [Repo Beats](#repo-beats)

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

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

## Usage Trend

[Usage Trend of graphql-request](https://npm-compare.com/graphql-request/#timeRange=THREE_YEARS)

![image](https://github.com/jasonkuhrt/graphql-request/assets/3455798/8d27c215-f20f-46f9-b38d-61f41d14882f)

## Node Version Support

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

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.

## Project Stats

### Package Installs

<a href="https://npm-compare.com/graphql-request#timeRange=FIVE_YEARS" target="_blank">
<img src="https://npm-compare.com/img/npm-trend/FIVE_YEARS/graphql-request.png" width="100%" alt="NPM Usage Trend of graphql-request" />
</a>

### Repo Beats

![Alt](https://repobeats.axiom.co/api/embed/aeb7beaee43b190e90868357c5a2898f517fb63e.svg "Repobeats analytics image")
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,26 @@
"release:pr": "dripip pr"
},
"dependencies": {
"@dprint/formatter": "^0.3.0",
"@dprint/typescript": "^0.91.1",
"@graphql-typed-document-node/core": "^3.2.0",
"@molt/command": "^0.9.0",
"dprint": "^0.46.2",
"zod": "^3.23.8"
},
"peerDependencies": {
"graphql": "14 - 16"
"graphql": "14 - 16",
"dprint": "^0.46.2",
"@dprint/formatter": "^0.3.0",
"@dprint/typescript": "^0.91.1"
},
"peerDependenciesMeta": {
"dprint": {
"optional": true
},
"@dprint/formatter": {
"optional": true
},
"@dprint/typescript": {
"optional": true
}
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
Expand Down
15 changes: 12 additions & 3 deletions src/layers/2_generator/files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createFromBuffer } from '@dprint/formatter'
import { getPath } from '@dprint/typescript'
import type { Formatter } from '@dprint/formatter'
import _ from 'json-bigint'
import fs from 'node:fs/promises'
import * as Path from 'node:path'
Expand All @@ -18,6 +17,16 @@ export interface Input {
errorTypeNamePattern?: OptionsInput['errorTypeNamePattern']
}

const getTypeScriptFormatter = async (): Promise<Formatter | undefined> => {
try {
const { createFromBuffer } = await import(`@dprint/formatter`)
const { getPath } = await import(`@dprint/typescript`)
return createFromBuffer(await fs.readFile(getPath()))
} catch (error) {
return undefined
}
}

export const generateFiles = async (input: Input) => {
const sourceDirPath = input.sourceDirPath ?? process.cwd()
const schemaPath = input.schemaPath ?? Path.join(sourceDirPath, `schema.graphql`)
Expand All @@ -31,7 +40,7 @@ export const generateFiles = async (input: Input) => {
customScalarCodecsFilePath.replace(/\.ts$/, `.js`),
)
const customScalarCodecsPathExists = await fileExists(customScalarCodecsFilePath)
const typeScriptFormatter = (input.format ?? true) ? createFromBuffer(await fs.readFile(getPath())) : undefined
const typeScriptFormatter = (input.format ?? true) ? await getTypeScriptFormatter() : undefined

const codes = generateCode({
name: input.name,
Expand Down

0 comments on commit 829028d

Please sign in to comment.