captbaritone / grats

Implementation-First GraphQL for TypeScript

Home Page:https://grats.capt.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`@gqlType` apparently wants to use the whole dockblock as the type's name

mandx opened this issue · comments

/**
 * @gqlType
 *
 * This is a note for myself
 */
export type Query = unknown;

/** @gqlField */
export function queryField(_: Query): string {
  return ''
}
Dumps this error
# ERROR MESSAGE
# =============

# Grats playground bug encountered. Please report this error:
# 
#  l@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2504646
# o@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2550813
# q@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2554958
# z@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2597543
# y@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2592981
# S@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2599039
# 8284/ue/r<@https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:41216
# ue@https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:41897
# 8284/qe/</o<@https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:43569
# 8284/qe/<@https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:43763
# 7781/run/<@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2227204
# run@https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2227180
# 

Playground link

The error dump doesn't give us much to work with, however, if we use this code:

/**
 * @gqlType
 *
 * ThisIsANoteForMyself
 */
export type Query = unknown;

/** @gqlField */
export function queryField(_: Query): string {
  return ''
}

We get this as the resulting schema:

type ThisIsANoteForMyself {
  queryField: String
}

Maybe @gqlType needs to take only until the next newline to extract the type's new name?

I think TypeScript's docblock parsing assumes the description comes before any tags. We can double check by logging what we see on this line in this case. Does it give multiple sections of description? If it does, I think your suggestion is good. We could use just the first line as our GraphQL name.

Assuming TypeScript only looks for the description before the tags:

What if we just check the typename value for any non-GraphQL-identifier characters (spaces/linebreaks) and report a helpful error right away rather than waiting for GraphQL validation.

That would prevent the error of us generating a name that's so broken is causes stuff to break. It could also let us provide a helpful error:

Unexpected invalid GraphQL name. If you are trying to define a GraphQL description, it must be placed it before any @ tags.

We should also document this limitation in this page: https://grats.capt.dev/docs/resolvers/descriptions

Aside. When I open the playground link you provided, I get a slightly different error message. It's basically the same, but also includes the actual error message from GraphQL JS. Maybe it got truncated/mangled by your copy/paste?

# ERROR MESSAGE
# =============

# Grats playground bug encountered. Please report this error:
# 
#  GraphQLError: Names must only contain [_a-zA-Z0-9] but "This is a note for myself" does not.
#     at o (https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2550813)
#     at new q (https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2554958)
#     at z (https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2597543)
#     at y (https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2592981)
#     at S (https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2599038)
#     at https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:41216
#     at ue (https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:41897)
#     at https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:43569
#     at https://grats.capt.dev/assets/js/8926b418.0a75dbcb.js:1:43763
#     at https://grats.capt.dev/assets/js/7492.5eb44cb1.js:28:2227204

Aside. When I open the playground link you provided, I get a slightly different error message. It's basically the same, but also includes the actual error message from GraphQL JS. Maybe it got truncated/mangled by your copy/paste?

Actually seems to be a browser bug. I mainly use Firefox, and I got the "truncated" error. When I opened the playground link with Chrome, I got the same error text as you did.