Skip to content

[libgraphql-macros] Explore usage of /// rustdoc comments as a way to support macro-visible comments in lieu of GraphQL #-based comments #41

Description

@jeffmo

Problem

Currently libgraphql-macros is unable to see "comments" in the graphql_schema! {} macro because:

  1. // rust comments aren't passed along in the proc_macro::TokenStream that is handed to the proc macro
  2. GraphQL style #-based comments don't really lex well since everything following the # token up until the newline needs to be treated as something like the content of a string, but TokenStream will lex them as straight-up Rust tokens; So (a) any characters that aren't valid Rust tokens will be rejected an (b) it's hard (maybe impossible) to reliably identify newlines and therefore hard to know when we've moved beyond the GraphQL-comment and onward to real syntax:
graphql_schema! { 
  # Like this: type Query {}
}

is hard to distinguish from

graphql_schema! {
  # Like this:
  type Query {}
}

Possible Improvement To Problem

Although // rust comments aren't visible in a TokenStream, /// rustdoc comments are! (They are translated to #[doc = "..."] before being tokenized and passed along to the TokenStream).

If possible, it may be an improvement to support and recommend that /// tokens should be used in lieu of GraphQL-style # comments in graphql_schema!{} inline syntax. This may allow macro users to define Rust-inline comments that can faithfully be re-printed and handled accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions