lib/graphql_grpc/schema.rb in graphql_grpc-0.1.3 vs lib/graphql_grpc/schema.rb in graphql_grpc-0.1.4

- old
+ new

@@ -21,10 +21,11 @@ # SOFTWARE. require 'google/protobuf/empty_pb' module GraphqlGrpc + # :nodoc: module Schema # TODO: Find better way to detect queries # Currently look for methods named 'get' or with no args def query?(name_sym, rpc_desc) name_sym.to_s.start_with?('get') || @@ -54,37 +55,39 @@ def to_function_types(ggg_function_hash) ggg_function_hash.values.sort_by(&:name).map(&:to_query_type).join("\n ") end def to_schema_query - return 'type Query {'\ + if gql_queries.empty? + 'type Query {'\ ' # """This gRPC stub does not contain any methods that are mapped to '\ 'GraphQL queries; this placeholder query field keeps the Query type from '\ 'being empty which can break tools (GraphiQL) which expect Query to contain '\ 'at least one field."""'\ ' '\ ' grpcPlacholder: Url'\ - '}' if gql_queries.empty? - - "type Query { #{to_function_types(gql_queries)} }" + '}' + else + "type Query { #{to_function_types(gql_queries)} }" + end end def to_schema_mutations return '' if gql_mutations.empty? "type Mutation { #{to_function_types(gql_mutations)} }" end def to_gql_schema - <<EOF + <<GRAPHQL_SCHEMA #{to_schema_types} #{to_schema_query} #{to_schema_mutations} schema { query: Query #{gql_mutations.empty? ? '' : 'mutation: Mutation'} } -EOF +GRAPHQL_SCHEMA end end end