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

[typescript-operations] Conditional directives are ignored on fields with alias #8461

Open
jnous-5 opened this issue Oct 7, 2022 · 0 comments
Labels
core Related to codegen core/cli

Comments

@jnous-5
Copy link

jnous-5 commented Oct 7, 2022

Describe the bug

The generated types for fields that use aliases don't contain the optional operator ?. This throws a ts error when strictNullChecks is enabled.

Your Example Website or App

https://stackblitz.com/edit/github-hxvpzz-f9camz?file=types.ts

Steps to Reproduce the Bug or Issue

  1. Go to document.graphql and see that we have 2 fields with and without aliases.
  2. Run yarn codegen
  3. Go to types.ts and notice that UserQuery.alias isn't an optional property whereas UserQuery.user works correctly.

Expected behavior

Expected to see something like below. Fields with conditional directives (with or without aliases) should work similary.

export type UserQuery = {
  __typename?: 'Query';
  alias?: { __typename?: 'User'; id: string; username: string; email: string };
  user?: { __typename?: 'User'; id: string; username: string; email: string };
};

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 16.16.0
  • graphql version: 16.6.0
  • @graphql-codegen/typescript-operations version(s): 2.5.3

Codegen Config File

No response

Additional context

Maybe we can pass the isConditional variable in L532. Currently, only the name has access on this.

const isConditional = hasConditionalDirectives(field) || inlineFragmentConditional;
linkFields.push({
- alias: field.alias ? this._processor.config.formatNamedField(field.alias.value, selectedFieldType) : undefined,
+ alias: field.alias ? this._processor.config.formatNamedField(field.alias.value, selectedFieldType, isConditional) : undefined,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli
Projects
None yet
Development

No branches or pull requests

2 participants