meabed / gqlts

Type safe Graphql Query Builder
https://gqlts.vercel.app
MIT License
25 stars 5 forks source link

Allow passing a custom `tsconfig`. #719

Open talentlessguy opened 1 year ago

talentlessguy commented 1 year ago

Hi,

I have a case where I want to use Pastel together with a GraphQL client that I have.

But right now it fails it to properly import (types are not resolved) because the generated index.d.ts imports from './schema' instead of './schema.js':

import {
  FieldsSelection,
  GraphqlOperation,
  ClientOptions,
  ClientRequestConfig,
  Observable,
} from '@gqlts/runtime'
import { Client as WSClient } from 'graphql-ws'
import { AxiosInstance } from 'axios'
export * from './schema' // should be `schema.js`

Would be nice to either respect the current tsconfig file or to be able to pass it in the library like this:

import { generate } from '@gqlts/cli'
import { printSchema } from 'graphql'
import { schema } from '@stauro/api'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const tsConfig = JSON.parse(await fs.readFile('./tsconfig.json', 'utf-8'))

await generate({
  schema: printSchema(schema),
  onlyEsModules: true,
  output: path.join(fileURLToPath(new URL('.', import.meta.url)), 'generated'),
  tsconfig,
})

my tsconfig:

{
  "compilerOptions": {
    "jsx": "react",
    "preserveSymlinks": true,
    "moduleResolution": "Node16",
    "module": "Node16"
  }
}
meabed commented 1 year ago

Thanks @talentlessguy sounds good, I will check this approach and add it

talentlessguy commented 1 year ago

awesome, thank you for a quick response!