Sha256: 5df6d330c29b677ddd6b0cf340693a9e9289a116f392ed94c167160569ec0af7
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module GraphQLDocs class Parser attr_reader :schema, :processed_schema def initialize(response, options) @options = options @schema = JSON.parse(response)['data'] @processed_schema = @schema.dup['__schema'] end def parse # sort the types @processed_schema['types'] = @processed_schema['types'].sort_by { |key, _| key['name'] } # fetch the connections @processed_schema['types'].each do |object| next if object['fields'].nil? object['connections'] = object['fields'].select { |f| next if f.is_a?(Array); connection?(f) } end # fetch the kinds of items type_kinds = @processed_schema['types'].map { |h| h['kind'] }.uniq type_kinds.each do |kind| @processed_schema["#{kind.downcase}_types"] = @processed_schema['types'].select { |t| t['kind'] == kind } end # TODO: should the 'types' key be deleted now? @processed_schema end private def connection?(hash) if hash['type']['ofType'] && hash['type']['ofType']['name'] && hash['type']['ofType']['name'].end_with?('Connection') true else false end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
graphql-docs-0.1.0 | lib/graphql-docs/parser.rb |