-
-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render directives at the top of the schema #1270
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,44 @@ object Rendering { | |
} | ||
.mkString("\n\n") | ||
|
||
def renderDirectives(directives: List[__Directive]): String = | ||
directives.map(renderDirective).mkString("\n") | ||
|
||
private def renderDirective(directive: __Directive): String = { | ||
val inputs = directive.args match { | ||
case i if i.nonEmpty => s"""(${i.map(renderInputValue).mkString(", ")})""" | ||
case _ => "" | ||
} | ||
val locationStrings = directive.locations.map { | ||
case __DirectiveLocation.QUERY => "QUERY" | ||
case __DirectiveLocation.MUTATION => "MUTATION" | ||
case __DirectiveLocation.SUBSCRIPTION => "SUBSCRIPTION" | ||
case __DirectiveLocation.FIELD => "FIELD" | ||
case __DirectiveLocation.FRAGMENT_DEFINITION => "FRAGMENT_DEFINITION" | ||
case __DirectiveLocation.FRAGMENT_SPREAD => "FRAGMENT_SPREAD" | ||
case __DirectiveLocation.INLINE_FRAGMENT => "INLINE_FRAGMENT" | ||
case __DirectiveLocation.SCHEMA => "SCHEMA" | ||
case __DirectiveLocation.SCALAR => "SCALAR" | ||
case __DirectiveLocation.OBJECT => "OBJECT" | ||
case __DirectiveLocation.FIELD_DEFINITION => "FIELD_DEFINITION" | ||
case __DirectiveLocation.ARGUMENT_DEFINITION => "ARGUMENT_DEFINITION" | ||
case __DirectiveLocation.INTERFACE => "INTERFACE" | ||
case __DirectiveLocation.UNION => "UNION" | ||
case __DirectiveLocation.ENUM => "ENUM" | ||
case __DirectiveLocation.ENUM_VALUE => "ENUM_VALUE" | ||
case __DirectiveLocation.INPUT_OBJECT => "INPUT_OBJECT" | ||
case __DirectiveLocation.INPUT_FIELD_DEFINITION => "INPUT_FIELD_DEFINITION" | ||
} | ||
val directiveLocations = locationStrings.mkString(" | ") | ||
|
||
val body = s"""directive @${directive.name}${inputs} repeatable on ${directiveLocations}""".stripMargin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh shoot I meant to ask about this. Right now it's hard-coded as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah this keyword is new in the 2021 spec, which is why it was not there before. Would be nice to add (otherwise, don't include the keyword). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, let me see what I can do about adding it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the top of my head, it should be added in the parser, in the If that's too much, it can be done in another PR 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Yeah I will remove the |
||
|
||
renderDescription(directive.description) match { | ||
case "" => body | ||
case something => something + body | ||
} | ||
} | ||
|
||
private def renderInterfaces(t: __Type): String = | ||
t.interfaces() | ||
.fold("")(_.flatMap(_.name) match { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy paste to the
__DirectiveLocation
code. Wasn't sure if we wanted to somehow encode the string version of the location in thecase object
?