Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Romanchuk opened this issue Jul 28, 2022 · 9 comments
Milestone

Comments

@Romanchuk
Copy link

Romanchuk commented Jul 28, 2022

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.

@capaj
Copy link
Owner

capaj commented Oct 3, 2022

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

dotansimha/graphql-code-generator#7017

@capaj capaj added this to the 1.1.0 milestone Oct 3, 2022
@neongreen
Copy link

neongreen commented Jan 20, 2023

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
Copy link
Owner

capaj commented Jan 20, 2023

@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
Copy link
Owner

capaj commented Jan 20, 2023

@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
Copy link
Owner

capaj commented Jan 20, 2023

@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
Copy link

@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
Copy link

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

@capaj
Copy link
Owner

capaj commented Feb 24, 2023

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

Will try next weekend.

@howells
Copy link

howells commented Jul 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants