在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gjtorikian/graphql-docs开源软件地址(OpenSource Url):https://github.com/gjtorikian/graphql-docs开源编程语言(OpenSource Language):Ruby 56.8%开源软件介绍(OpenSource Introduction):GraphQLDocsEasily generate beautiful documentation from your GraphQL schema. InstallationAdd this line to your application's Gemfile: gem 'graphql-docs' And then execute:
Or install it yourself as:
Usage# pass in a filename
GraphQLDocs.build(filename: filename)
# or pass in a string
GraphQLDocs.build(schema: contents)
# or a schema class
schema = GraphQL::Schema.define do
query query_type
end
GraphQLDocs.build(schema: schema) BreakdownThere are several phases going on the single
If you wanted to, you could break these calls up individually. For example: options = {}
options[:filename] = "#{File.dirname(__FILE__)}/../data/graphql/schema.idl"
options[:renderer] = MySuperCoolRenderer
options = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge(options)
response = File.read(options[:filename])
parser = GraphQLDocs::Parser.new(response, options)
parsed_schema = parser.parse
generator = GraphQLDocs::Generator.new(parsed_schema, options)
generator.generate Generating outputBy default, the HTML generation process uses ERB to layout the content. There are a bunch of default options provided for you, but feel free to override any of these. The Configuration section below has more information on what you can change. It also uses html-pipeline to perform the rendering by default. You can override this by providing a custom rendering class.You must implement two methods:
class CustomRenderer
def initialize(parsed_schema, options)
@parsed_schema = parsed_schema
@options = options
end
def render(contents, type: nil, name: nil)
contents.sub(/Repository/i, '<strong>Meow Woof!</strong>')
opts[:content] = contents
@graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
end
end
options[:filename] = 'location/to/sw-api.graphql'
options[:renderer] = CustomRenderer
GraphQLDocs.build(options) If your TemplatesThe layouts for the individual GraphQL pages are ERB templates, but you can also use ERB templates for your static landing pages. If you want to add additional variables for your landing pages, you can add define a Helper methodsIn your ERB layouts, there are several helper methods you can use. The helper methods are:
To call these methods within templates, you must use the dot notation, such as ConfigurationThe following options are available:
Customizing NoticesA notice is a block of CommonMark text that optionally has a title which is displayed above a schema member's description. The look of a notice block can be controlled by specifying a custom class for it and then styled via CSS. The The proc will be called for each schema member and needs to return an array of notices or an empty array if there are none. A
Example of a options[:notices] = ->(schema_member_path) {
notices = []
if schema_member_path == "TeamDiscussion"
notices << {
class: "preview-notice",
body: "Available via the [Team Discussion](/previews/team-discussion) preview.",
}
end
notices
} The format of "Author", # an object
"ExtraInfo" # an interface,
"Author.socialSecurityNumber" # a field
"Book.author.includeMiddleInitial" # an argument
"Likeable" # a union,
"Cover" # an enum
"Cover.DIGITAL" # an enum value
"BookOrder" # an input object
"Mutation.addLike" # a mutation DevelopmentAfter checking out the repo, run Sample siteClone this repository and run:
to see some sample output. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论