Sha256: e0e4651fd45ff1417bce19a93696b4dd947daaf013d6f7004d86e48ad9013390

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

require 'graphql-idl-parser/graphqlidlparser'
require 'graphql-idl-parser/version'

module GraphQL
  class IDLParser
    def initialize(filename: nil, schema: nil)
      if !filename.nil? && !schema.nil?
        raise ArgumentError, 'Pass in `filename` or `schema`, but not both!'
      end

      if filename.nil? && schema.nil?
        raise ArgumentError, 'Pass in either `filename` or `schema`'
      end

      if filename
        unless filename.is_a?(String)
          raise TypeError, "Expected `String`, got `#{filename.class}`"
        end

        unless File.exist?(filename)
          raise ArgumentError, "#{filename} does not exist!"
        end

        @schema = File.read(filename)
      else
        unless schema.is_a?(String)
          raise TypeError, "Expected `String`, got `#{schema.class}`"
        end

        @schema = schema
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-idl-parser-0.1.1 lib/graphql-idl-parser.rb
graphql-idl-parser-0.1.0 lib/graphql-idl-parser.rb
graphql-idl-parser-0.0.1 lib/graphql-idl-parser.rb