graphql-editor / graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native ( apollo compatible )
https://graphqleditor.com/docs/tools/zeus/index/
MIT License
1.94k stars 105 forks source link

[FEAT] improve and proper export of ValueTypes #361

Open Hulkmaster opened 1 year ago

Hulkmaster commented 1 year ago

one of my colleagues found ValueTypes and its super useful

for example if i have params for mutation i can just use ValueTypes['myMutationParams']

but that was found inside the lib and it lacks some basic types

I would like to see it as part of official docs and officially supported feature, because it allows me to make consistent TS for api without need for manual rewriting

Our example:

Before

export interface ICreateCampaignPayload {
  input: {
    forwardUrl: string,
    name: string,
    timeframe: {
      startsAt: string,
      endsAt?: string,
    },
    manualInactive?: boolean,
  },
  tenantId: string,
}

After

export interface ICreateCampaignPayload {
  input: ValueTypes['CreateCampaignInput'],
  tenantId: string,
}

Perfectly (but not possible with current implementation)

export interface ICreateCampaignPayload extends ValueTypes['CreateCampaignPayload'] {}

(here i meant that it would be used directly, but for better comparison readability used extend)

Usage

export function apiCreateCampaign(payload: ICreateCampaignPayload) {
  return graphqlClient('mutation', {
    scalars,
  })({
    createCampaign: [
      {
        ...payload,
      },
      {
        ...campaignQuery.campaign,
      },
    ],
  });
}