capaj / graphql-codegen-vscode

vscode extension which runs graphql-codegen whenever you save a query/mutation
https://marketplace.visualstudio.com/items?itemName=capaj.graphql-codegen-vscode
MIT License
68 stars 10 forks source link

Extensions config file search logic is not compatible with graphql-code-generator config search #21

Open Romanchuk opened 2 years ago

Romanchuk commented 2 years ago

I've struggled when trying to use single graphql config file for all vscode extensions (graphql releated):

graphql.vscode-graphql and @graphql-codegen/cli both searching configs by graphql-config rules

So for example if you have graphql.config.js file for config.

but graphql-codegen-vscode won't, because it doesnt relay on @graphql-codegen/cli config search, it has it's own generateSearchPlaces.ts

So to setup "single" config i dive into graphql-codegen-vscode and found out that it has over config search logic. According to it i created codegen.js with content:

import conf from './graphql.config';

module.exports = {
    ...conf
};

Not very clean... Also until i created that file graphql-codegen-vscode didn't even alert that it can't find config. It just didn't run silently.

From my perspective as a creators of a 3rd party libraries/extensions based on a some original lib we should not override native/original logic. Because if we do - user of our lib must know docs of original lib and also our docs (if it exists). And our library inevitably will go out of date or you will need keep an eye on each release and sync your code with original.

So graphql-codegen-vscode should not override native behavior of @graphql-codegen/cli tooling. In that particular case - should not have alternative config search.

capaj commented 2 years ago

oh yeah I will import the function from graphql-codegen as my PR was merged:

https://github.com/dotansimha/graphql-code-generator/pull/7017

neongreen commented 1 year ago

Looks like I'm hitting this as well:

image

I'm using the new client preset and so my config is called codegen.ts.

capaj commented 1 year ago

@neongreen this is interesting. I will put guard in place for this type error to never happen, but it's weird, because according to graphql-codegen/cli a config object should be always returned

image

capaj commented 1 year ago

@neongreen in 1.1.0 it won't find find your config anyway, but at least the type error should be fixed. BTW what config do you use? generateSearchPlaces.ts is exact copy of @graphql-codegen/cli so it should be able to find all the config files the same.

capaj commented 1 year ago

@Romanchuk

graphql-codegen-vscode didn't even alert that it can't find config. It just didn't run silently.

In 1.1.0 it should tell you that config was not found, when you explicitly run the command.

neongreen commented 1 year ago

@capaj here's my config:

// codegen.ts

import type { CodegenConfig } from '@graphql-codegen/cli'
import { printSchema } from 'graphql'
import { schema } from '@lib/graphql/schema'

const config: CodegenConfig = {
  schema: printSchema(schema),
  documents: ['{components,lib,pages}/**/!(*.graphql).{ts,tsx}'],
  generates: {
    './generated/graphql/': {
      preset: 'client',
      plugins: [],
    },
  },
}

export default config

I also have a graphql.config.json but I'm not sure if that's relevant. Although tbh now I'm not 100% sure which config the extension is looking for — is it the codegen config or the "single" graphql-config config?

neongreen commented 1 year ago

Update: after upgrading to 1.1.0 I'm getting a different error, see #29.

capaj commented 1 year ago

I haven't tested with a ts file as config. I always use yaml or json.

Will try next weekend.

howells commented 1 year ago

@capaj wondered if you managed to look into this? As far as I can tell it's just ignoring my codegen.ts file.