graphql-codegen-vscode icon indicating copy to clipboard operation
graphql-codegen-vscode copied to clipboard

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

Open Romanchuk opened this issue 2 years ago • 9 comments

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

  • graphql-codegen-vscode
  • graphql.vscode-graphql (Graphql language service)

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.

  • graphql.vscode-graphql (Graphql language service) will find it
  • @graphql-codegen/cli fill find it (run npm exec -- graphql-codegen)

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.

Romanchuk avatar Jul 28 '22 05:07 Romanchuk

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

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

capaj avatar Oct 03 '22 07:10 capaj

Looks like I'm hitting this as well:

image

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

neongreen avatar Jan 20 '23 02:01 neongreen

@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 avatar Jan 20 '23 07:01 capaj

@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 avatar Jan 20 '23 10:01 capaj

@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.

capaj avatar Jan 20 '23 10:01 capaj

@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 avatar Jan 20 '23 11:01 neongreen

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

neongreen avatar Jan 20 '23 12:01 neongreen

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

Will try next weekend.

capaj avatar Feb 24 '23 10:02 capaj

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

howells avatar Jul 02 '23 16:07 howells