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

Possible to remove Maybe & Scalars types in favor of number | null and inlined Scalar values? #2048

Closed
ericbiewener opened this issue Jun 22, 2019 · 9 comments

Comments

@ericbiewener
Copy link

Rather than the creation of type Maybe<T> = T | null, is it possible to just inline the | null everywhere it is used? Same with the type Scalars. To clarify:

Current output:

Maybe<Scalars["String"]>

Desired output:

string | null

I'd also be interested to know if there is an advantage to the current approach.

@dotansimha
Copy link
Owner

Hi @ericbiewener , we are already thinking about adding this feature.
Please see my comment here: #1904 (comment)

@cothman
Copy link

cothman commented Dec 19, 2019

Same here, is the Maybe type removed or at least configurable!

Let's suppose I'm developing a Service Layer that handles the service layer communication and all I want are types to type my queries or mutation.
It's a headache if I want to use generated types without using generated queries or mutation.

Here's a case where I'm typing my state depending on query's result.

type TopicsState = {
  suggestedTopics: Maybe<DisplaySuggestedTopic>[] | null | undefined;
};

@omarbenmegdoul
Copy link

omarbenmegdoul commented May 18, 2022

Is this still in the cards, or perhaps already implemented? If not, is it doable for me to create a plugin to achieve this? @dotansimha is #1904 really the same problem? Seems like it was dealt with but this one remains

@adamtaylor13
Copy link

I looked at #2107, and it doesn't seem to resolve the originally asked question. Ideally, I'd like for the generated type files to just inline Maybe whenever possible. For example, currently the behavior is:

export type Maybe<T> = T | undefined;
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
  ID: string;
  String: string;
  Boolean: boolean;
  Int: number;
  Float: number;
};
export type User = {
  __typename?: 'User';
  email: Scalars['String'];
  id: Scalars['String'];
  name: Scalars['String'];
  profilePictureUrl?: Maybe<Scalars['String']>;
};

But, I'd really like to ability to simply generate:

export type User = {
  __typename?: 'User';
  email: string;
  id: string;
  name: string;
  profilePictureUrl?: string | undefined;
};

Is there some trade-off here between the two that I don't understand?

@ryancarloscorrea
Copy link

@adamtaylor13 Did you find any solution?

@adamtaylor13
Copy link

@ryancarloscorrea Unfortunately not ☹️

@venkatd
Copy link

venkatd commented Aug 24, 2023

I would like the same as @adamtaylor13 the readability of the types is more confusing for others on our team and simply inlining the types (as though I was writing them by hand) would be the ideal.

I could hack it with some regexp find/replace but would rather have an option for this!

What is the advantage to having the extra scalars layer?

@denakol
Copy link

denakol commented Sep 19, 2023

Hi! no news regarding it? Types are quite ugly.

@jhopley-stadion
Copy link

Yea it would be pretty good to have config to remove this. Really annoying and forcing me to cast types when doing transforms,

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

9 participants