Skip to content

Support for @ in descriptions #179

@louy

Description

@louy

According to the docs, @ in description comments makes the comment get truncated

Depending upon your version of TypeScript, descriptions with a @ symbol in their text, for example a GitHub handle, may get truncated. To avoid this, you can wrap the tag in quotes or backticks.

/** This comment was added by `@captbaritone`. */

This limitation makes it impossible to put GraphQL example code in documentation comments.

For example, take the native @semanticNonNull that grats ships with. This is impossible to declare using grats:

import {Int} from 'grats';
/**
 * Indicates that a position is semantically non null: it is only null if there is a matching error in the `errors` array.
 * In all other cases, the position is non-null.
 *
 * Tools doing code generation may use this information to generate the position as non-null if field errors are handled out of band:
 *
 * ```graphql
 * type User {
 *     # email is semantically non-null and can be generated as non-null by error-handling clients.
 *     email: String @semanticNonNull
 * }
 * ```
 *
 * The `levels` argument indicates what levels are semantically non null in case of lists:
 *
 * ```graphql
 * type User {
 *     # friends is semantically non null
 *     friends: [User] @semanticNonNull # same as @semanticNonNull(levels: [0])
 *
 *     # every friends[k] is semantically non null
 *     friends: [User] @semanticNonNull(levels: [1])
 *
 *     # friends as well as every friends[k] is semantically non null
 *     friends: [User] @semanticNonNull(levels: [0, 1])
 * }
 * ```
 *
 * `levels` are zero indexed.
 * Passing a negative level or a level greater than the list dimension is an error.
 * @gqlDirective on FIELD_DEFINITION
 */
export function semanticNonNull({ levels = [0] }: { levels: Int[] }) {}

Produces a truncated description:

"""
Indicates that a position is semantically non null: it is only null if there is a matching error in the `errors` array.
In all other cases, the position is non-null.

Tools doing code generation may use this information to generate the position as non-null if field errors are handled out of band:

```graphql
type User {
    # email is semantically non-null and can be generated as non-null by error-handling clients.
    email: String
"""
directive @semanticNonNull(levels: [Int!]! = [0]) on FIELD_DEFINITION

Afaik there is currently no work around in grats to produce the desired output.

Playground reproduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions