graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Extend typescript-operations to support directives for operationResultType

Open larsenwork opened this issue 5 years ago • 7 comments

Is your feature request related to a problem? Please describe.

In my frontend I'm consuming a schema that uses @deprecated directives. Ultimately I'd like to get eslint warnings if I'm consuming a deprecated value using https://github.com/gund/eslint-plugin-deprecation#setup

Example code:

type DemoThing {
  thingV1: string! @deprecated(reason: "thingV1 is old, use thingV2")
  thingV2: string!
}

which generates

export type DemoThing = {
  /** @deprecated thingV1 is old, use thingV2 */
  thingV1: string
  thingV2: string
}

but when I make a query that includes that — e.g.

query getDemoThing {
  thingV1
  thingV2
}

I don't get the deprecation JSDoc. It generates:

export type GetDemoThingQuery = {
  thingV1: string
  thingV2: string
}

Describe the solution you'd like

export type GetDemoThingQuery = {
+  /** @deprecated thingV1 is old, use thingV2 */
  thingV1: string
  thingV2: string
}

Describe alternatives you've considered

None 😅


Additional context

I'm using

    plugins:
      - typescript
      - typescript-operations
      - typescript-react-query

I'd love to help out implementing this if deemed valuable/doable. Particularly if I get a few pointers.

larsenwork avatar Sep 14 '21 12:09 larsenwork

I am not sure I understand your problem. Could you elaborate?

ardatan avatar Sep 14 '21 12:09 ardatan

@ardatan thanks, and sure:

Current setup

Ultimately I'm fetching data with the hooks generated using typescript-react-query. In the example above I'd consume the hook like this

const { data } = useGetDemoThingQuery()

the type for data will then be optional GetDemoThingQuery that doesn't have the JSDoc annotation inside it. So when in consume data?.thingV1 it's not marked as deprecated.

My wish

That the GetDemoThingQuery includes the JSDoc comment so I can set up tooling to warn me when I consume data?.thingV2

larsenwork avatar Sep 14 '21 13:09 larsenwork

So with

export type GetDemoThingQuery = {
  /** @deprecated thingV1 is old, use thingV2 */
  thingV1: string
  thingV2: string
}

I could get something like this and have my CI block/warn when doing frontend releases that I'm consuming something that was marked as deprecated by the API.

image

larsenwork avatar Sep 14 '21 13:09 larsenwork

@dotansimha @ardatan it seems reasonable to me, please let me know if it doesn't make sense?

@larsenwork want to start working on it?

Urigo avatar Sep 17 '21 23:09 Urigo

@Urigo sure, it'd speed up my process greatly with some pointers where to start 👀 — i.e. if it's in the typescript-operations package or somewhere else.

larsenwork avatar Oct 04 '21 07:10 larsenwork

I too have just realised deprecations are missing from typescript-operations, and that any deprecations wouldn't flow from api to consumers using this tooling.

zomble avatar Mar 15 '22 09:03 zomble

@zomble yeah, it's a bit unfortunate. However without pointers I'd be a bit hard pressed to start fixing it but I could actually dedicate some office time to it this week if given a tiny pointer or two @Urigo ? 😄

larsenwork avatar Mar 15 '22 09:03 larsenwork