question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: Use Pick<T, K> to generate query types

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently, we just have a copy of original type for a query

Describe the solution you’d like I think a more clear approach would be to use Pick<T, K> operator to make a connection to the original type.

So this would be like this

export interface TypeA {
  id: string;
  name: string;
  age: number;
}

export namespace MyQuery {
  export type TypeA = Pick<TypeA, 'id' | 'name'>
}

See it’s in action here https://medium.com/@curtistatewilkinson/typescript-2-1-and-the-power-of-pick-ff433f1e6fb

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
itscarlosrufocommented, Jan 31, 2019

Plugin typescript-client

I’ve been taking a look to this feature proposal, the idea of using Pick it’s quite interesting as y’all have mentioned before. I’d love to discuss what would be the best way implement this, as I have no much idea about the library, I’d really appreciate your opinion & hopefully guidance. I’ve noticed that the typescript-client is the responsible for generating the types that’d change, refactoring its handlebar template it’d probably work but yep, surely I’m missing a lot of corner cases.

Check this example out and let’s discuss how we could solve it, the proposal is tested & working with typescript-react-apollo with no changes in its template.

Query

query allRockets {
  rockets {
    id
    name
    first_stage {
      reusable
      engines
    }
  }
}

Current Types

export type AllRocketsVariables = {};

export type AllRocketsQuery = {
  __typename?: 'Query';
  rockets: Maybe<AllRocketsRockets[]>;
};

export type AllRocketsRockets = {
  __typename?: 'Rocket';
  id: Maybe<string>;
  name: Maybe<string>;
  first_stage: Maybe<AllRocketsFirstStage>;
};

export type AllRocketsFirstStage = {
  __typename?: 'RocketFirstStage';
  reusable: Maybe<boolean>;
  engines: Maybe<number>;
};

Proposal Iterate over the fields until all of them are primitive types (didn’t code it yet but I guess this is possible), it’d require to include the typescript-server in order to generate & pick the interfaces! Probably the Pick types have to include Maybe types too.

export type AllRocketsVariables = {};

export type AllRocketsQuery = {
  __typename?: 'Query';

  rockets: Maybe<AllRocketsRockets[]>;
};

export type AllRocketsRockets = Pick<Rocket, 'id' | 'name' | 'first_stage'> & {
  first_stage: Pick<RocketFirstStage, 'reusable' | 'engines'>;
};

cc/ @dotansimha @ardatan

Help wanted hahah 🙏🏻

1reaction
esamattiscommented, Mar 20, 2019

Will do

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics
This schema defines a hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which...
Read more >
Generating Query Suggestions to Support Task-Based Search
ABSTRACT. We address the problem of generating query suggestions to support users in completing their underlying tasks (which motivated them.
Read more >
Query Suggestions in InstantSearch.js - Algolia
Query Suggestions is a search experience that displays a list of possible queries that your users can select from as they type.
Read more >
Unable to find any GraphQL type definitions for the following ...
I suggest thay you create a new file with a simple query, ... queries and mutations and use the codegen to generate the...
Read more >
SQL IntelliSense and Autocomplete in SSMS | Redgate
You can also use it in a way that it both makes code suggestions ... To get the same information for a procedure,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found