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

Documentation or Explanation on how to create Types during development #354

Closed pscanlon1 closed 1 year ago

pscanlon1 commented 1 year ago

I have hesitated to ask this. Been using the library for a while and its super helpful. I am just trying to figure out how I can extend something to a custom class to have the types available during development..

Simple example using fictitious service that returns daily stock prices:

My selector:

{
      stocks: [
        {
          where: {
            symbol: { _eq: 'AAPL' },
          },
        },
        {
            symbol: true,
            price: true,
            date: true.
        }
      ],
}

How can I create a class that extends the typeof this selector?

I have created Selectors using

const selectorForStock = Selector('stocks')({symbol: true, price: true, date: true})

I would like to use in another class like

export class MyStocks extends <How do I extend the return type here!> {
     someCalculatedField: number;
     constructor(data: <how do I get the type here!>){
          Object.assign(this,data);
          this.someCalculatedField = this.price * 50; // this.price's type should be 'number'
     }
}

TypeFromSelector? FromSelector?

The closest i can get is something like. data.map(d=>TypeFromSelector('stocks')(d)) and then d.symbol's type is a string.

Thanks for help and sorry for creating an issue that is more about docs.

aexol commented 1 year ago

Use Selector to create it https://graphqleditor.com/docs/tools/zeus/basics/selector/