convert Active Record type to GraphQL type
509427
def convert_type type
      return type if type.is_a? GraphQL::BaseType

      unless type.is_a? Symbol
        type = type.to_s.downcase.to_sym
      end

      {
        boolean: GraphQL::BOOLEAN_TYPE,
        date: GraphQL::Types::DATE,
        datetime: GraphQL::Types::ISO8601DateTime,
        decimal: GraphQL::Types::DECIMAL,
        float: GraphQL::FLOAT_TYPE,
        int: GraphQL::INT_TYPE,
        integer: GraphQL::INT_TYPE,
        json: GraphQL::Types::JSON,
        string: GraphQL::STRING_TYPE,
        text: GraphQL::STRING_TYPE,
      }[type]
    end
1084131
function getSchema(mongooseModels, options) {
  if (!isArray(mongooseModels)) {
    mongooseModels = [mongooseModels];
  }
  const graffitiModels = model.getModels(mongooseModels);
  const fields = getFields(graffitiModels, options);
  return new GraphQLSchema(fields);
}
44623
private function getResourceObjectType(?string $resourceClass, ResourceMetadata $resourceMetadata, bool $input, ?string $queryName, ?string $mutationName, bool $wrapped = false, int $depth = 0): GraphQLType
    {
        $shortName = $resourceMetadata->getShortName();

        if (null !== $mutationName) {
            $shortName = $mutationName.ucfirst($shortName);
        }
        if ($input) {
            $shortName .= 'Input';
        } elseif (null !== $mutationName) {
            if ($depth > 0) {
                $shortName .= 'Nested';
            }
            $shortName .= 'Payload';
        }
        if ($wrapped && null !== $mutationName) {
            $shortName .= 'Data';
        }

        if (isset($this->graphqlTypes[$shortName])) {
            return $this->graphqlTypes[$shortName];
        }

        $ioMetadata = $resourceMetadata->getGraphqlAttribute(null === $mutationName ? 'query' : $mutationName, $input ? 'input' : 'output', null, true);
        if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null !== $ioMetadata['class']) {
            $resourceClass = $ioMetadata['class'];
        }

        $wrapData = !$wrapped && null !== $mutationName && !$input && $depth < 1;

        $configuration = [
            'name' => $shortName,
            'description' => $resourceMetadata->getDescription(),
            'resolveField' => $this->defaultFieldResolver,
            'fields' => function () use ($resourceClass, $resourceMetadata, $input, $mutationName, $queryName, $wrapData, $depth, $ioMetadata) {
                if ($wrapData) {
                    $queryNormalizationContext = $resourceMetadata->getGraphqlAttribute($queryName ?? 'query', 'normalization_context', [], true);
                    $mutationNormalizationContext = $resourceMetadata->getGraphqlAttribute($mutationName ?? '', 'normalization_context', [], true);
                    // Use a new type for the wrapped object only if there is a specific normalization context for the mutation.
                    // If not, use the query type in order to ensure the client cache could be used.
                    $useWrappedType = $queryNormalizationContext !== $mutationNormalizationContext;

                    return [
                        lcfirst($resourceMetadata->getShortName()) => $useWrappedType ?
                            $this->getResourceObjectType($resourceClass, $resourceMetadata, $input, $queryName, $mutationName, true, $depth) :
                            $this->getResourceObjectType($resourceClass, $resourceMetadata, $input, $queryName, null, true, $depth),
                        'clientMutationId' => GraphQLType::string(),
                    ];
                }

                return $this->getResourceObjectTypeFields($resourceClass, $resourceMetadata, $input, $queryName, $mutationName, $depth, $ioMetadata);
            },
            'interfaces' => $wrapData ? [] : [$this->getNodeInterface()],
        ];

        return $this->graphqlTypes[$shortName] = $input ? GraphQLType::nonNull(new InputObjectType($configuration)) : new ObjectType($configuration);
    }
1260955
private <T> GraphRequest<T> graph(String object, JavaType type, Param... params) {
		this.checkForBatchExecution();
		
		// The data is transformed through a chain of wrappers
		GraphRequest<T> req =
			new GraphRequest<T>(object, params, this.mapper, this.<T>createMappingChain(type));
		
		this.graphRequests.add(req);
		return req;
	}
697547
function reducer (type, records) {
      return reduce(records, function (hash, record) {
        record = outputRecord.call(self, type, msgpack.decode(record))
        hash[record[primaryKey]] = record
        return hash
      }, {})
    }
491362
def _get_fields_for_class(schema_graph, graphql_types, field_type_overrides, hidden_classes,
                          cls_name):
    """"""
    properties = schema_graph.get_element_by_class_name(cls_name).properties

    # Add leaf GraphQL fields (class properties).
    all_properties = {
        property_name: _property_descriptor_to_graphql_type(property_obj)
        for property_name, property_obj in six.iteritems(properties)
    }
    result = {
        property_name: graphql_representation
        for property_name, graphql_representation in six.iteritems(all_properties)
        if graphql_representation is not None
    }

    # Add edge GraphQL fields (edges to other vertex classes).
    schema_element = schema_graph.get_element_by_class_name(cls_name)
    outbound_edges = (
        ('out_{}'.format(out_edge_name),
         schema_graph.get_element_by_class_name(out_edge_name).properties[
             EDGE_DESTINATION_PROPERTY_NAME].qualifier)
        for out_edge_name in schema_element.out_connections
    )
    inbound_edges = (
        ('in_{}'.format(in_edge_name),
         schema_graph.get_element_by_class_name(in_edge_name).properties[
             EDGE_SOURCE_PROPERTY_NAME].qualifier)
        for in_edge_name in schema_element.in_connections
    )
    for field_name, to_type_name in chain(outbound_edges, inbound_edges):
        edge_endpoint_type_name = None
        subclasses = schema_graph.get_subclass_set(to_type_name)

        to_type_abstract = schema_graph.get_element_by_class_name(to_type_name).abstract
        if not to_type_abstract and len(subclasses) > 1:
            # If the edge endpoint type has no subclasses, it can't be coerced into any other type.
            # If the edge endpoint type is abstract (an interface type), we can already
            # coerce it to the proper type with a GraphQL fragment. However, if the endpoint type
            # is non-abstract and has subclasses, we need to return its subclasses as an union type.
            # This is because GraphQL fragments cannot be applied on concrete types, and
            # GraphQL does not support inheritance of concrete types.
            type_names_to_union = [
                subclass
                for subclass in subclasses
                if subclass not in hidden_classes
            ]
            if type_names_to_union:
                edge_endpoint_type_name = _get_union_type_name(type_names_to_union)
        else:
            if to_type_name not in hidden_classes:
                edge_endpoint_type_name = to_type_name

        if edge_endpoint_type_name is not None:
            # If we decided to not hide this edge due to its endpoint type being non-representable,
            # represent the edge field as the GraphQL type List(edge_endpoint_type_name).
            result[field_name] = GraphQLList(graphql_types[edge_endpoint_type_name])

    for field_name, field_type in six.iteritems(field_type_overrides):
        if field_name not in result:
            raise AssertionError(u'Attempting to override field "{}" from class "{}", but the '
                                 u'class does not contain said field'.format(field_name, cls_name))
        else:
            result[field_name] = field_type

    return result
200836
function processInputObjectType(object: GraphQLInputObjectType) {
  return reduce(object._typeConfig, (def, value, key) => {
    if (value !== undefined) {
      switch (key) {
        case 'fields':
          def.fields = reduce(object.getFields(), (fields, field, name) => {
            fields[name] = processArg(field).arg;
            return fields;
          }, Object.create(null));
          break;
        case 'description':
          set(def, key, value, (value !== ''));
          break;
        case 'astNode':
          const directives = extractDirectives(get(object, [ 'astNode' ]));
          set(def, '@directives', directives, Boolean(directives));
          break;
        default:
          break;
      }
    }
    return def;
  }, {
    type: 'Input'
  });
}
328930
def get_field_def(
    schema,  # type: GraphQLSchema
    parent_type,  # type: Union[GraphQLInterfaceType, GraphQLObjectType]
    field_ast,  # type: Field
):
    # type: (...) -> Optional[GraphQLField]
    """"""
    name = field_ast.name.value
    if name == "__schema" and schema.get_query_type() == parent_type:
        return SchemaMetaFieldDef

    elif name == "__type" and schema.get_query_type() == parent_type:
        return TypeMetaFieldDef

    elif name == "__typename" and isinstance(
        parent_type, (GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType)
    ):
        return TypeNameMetaFieldDef

    elif isinstance(parent_type, (GraphQLObjectType, GraphQLInterfaceType)):
        return parent_type.fields.get(name)
1304891
def get_field_def(
    schema: GraphQLSchema, parent_type: GraphQLType, field_node: FieldNode
) -> Optional[GraphQLField]:
    
    name = field_node.name.value
    if name == "__schema" and schema.query_type is parent_type:
        return SchemaMetaFieldDef
    if name == "__type" and schema.query_type is parent_type:
        return TypeMetaFieldDef
    if name == "__typename" and is_composite_type(parent_type):
        return TypeNameMetaFieldDef
    if is_object_type(parent_type) or is_interface_type(parent_type):
        parent_type = cast(Union[GraphQLObjectType, GraphQLInterfaceType], parent_type)
        return parent_type.fields.get(name)
    return None
1116101
def to_definition(schema, printer: nil, **args)
      printer ||= GraphQL::Schema::Printer.new(schema, **args)
      printer.print_type(self)
    end
273339
def to_mysql_belongs_to(name, options = {})
      field "#{name}_id", type: Integer
      object_class = options[:class] || name.to_s.titleize.delete(' ').constantize
      self.instance_eval do
        define_method(name) do |reload = false|
          if reload
            self.instance_variable_set("@#{name}", nil)
          end

          if self.instance_variable_get("@#{name}").blank? 
            self.instance_variable_set("@#{name}", object_class.where(object_class.primary_key => self.send("#{name}_id")).first)
          end

          self.instance_variable_get("@#{name}")
        end

        define_method("#{name}=(new_instance)") do
          self.send("#{name}_id=", new_instance.id)
          self.instance_variable_set("@#{name}", nil)
        end
      end
    end
1335190
def lexicographic_sort_schema(schema: GraphQLSchema) -> GraphQLSchema:
    """"""

    def replace_type(type_):
        if is_list_type(type_):
            return GraphQLList(replace_type(type_.of_type))
        elif is_non_null_type(type_):
            return GraphQLNonNull(replace_type(type_.of_type))
        else:
            return replace_named_type(type_)

    def replace_named_type(type_: GraphQLNamedType) -> GraphQLNamedType:
        return type_map[type_.name]

    def replace_maybe_type(maybe_type):
        return maybe_type and replace_named_type(maybe_type)

    def sort_directive(directive):
        kwargs = directive.to_kwargs()
        kwargs.update(
            locations=sorted(directive.locations, key=sort_by_name_key),
            args=sort_args(directive.args),
        )
        return GraphQLDirective(**kwargs)

    def sort_args(args_map):
        args = {}
        for name, arg in sorted(args_map.items()):
            kwargs = arg.to_kwargs()
            kwargs.update(type_=replace_type(arg.type))
            args[name] = GraphQLArgument(**kwargs)
        return args

    def sort_fields(fields_map):
        fields = {}
        for name, field in sorted(fields_map.items()):
            kwargs = field.to_kwargs()
            kwargs.update(type_=replace_type(field.type), args=sort_args(field.args))
            fields[name] = GraphQLField(**kwargs)
        return fields

    def sort_input_fields(fields_map):
        return {
            name: GraphQLInputField(
                replace_type(field.type),
                description=field.description,
                default_value=field.default_value,
                ast_node=field.ast_node,
            )
            for name, field in sorted(fields_map.items())
        }

    def sort_types(arr: List[GraphQLNamedType]) -> List[GraphQLNamedType]:
        return [
            replace_named_type(type_) for type_ in sorted(arr, key=sort_by_name_key)
        ]

    def sort_named_type(type_: GraphQLNamedType) -> GraphQLNamedType:
        if is_scalar_type(type_) or is_introspection_type(type_):
            return type_
        elif is_object_type(type_):
            kwargs = type_.to_kwargs()
            object_type = cast(GraphQLObjectType, type_)
            # noinspection PyTypeChecker
            kwargs.update(
                interfaces=lambda: sort_types(object_type.interfaces),  # type: ignore
                fields=lambda: sort_fields(object_type.fields),
            )
            return GraphQLObjectType(**kwargs)
        elif is_interface_type(type_):
            kwargs = type_.to_kwargs()
            interface_type = cast(GraphQLInterfaceType, type_)
            kwargs.update(fields=lambda: sort_fields(interface_type.fields))
            return GraphQLInterfaceType(**kwargs)
        elif is_union_type(type_):
            kwargs = type_.to_kwargs()
            union_type = cast(GraphQLUnionType, type_)
            # noinspection PyTypeChecker
            kwargs.update(types=lambda: sort_types(union_type.types))  # type: ignore
            return GraphQLUnionType(**kwargs)
        elif is_enum_type(type_):
            kwargs = type_.to_kwargs()
            enum_type = cast(GraphQLEnumType, type_)
            kwargs.update(
                values={
                    name: GraphQLEnumValue(
                        val.value,
                        description=val.description,
                        deprecation_reason=val.deprecation_reason,
                        ast_node=val.ast_node,
                    )
                    for name, val in sorted(enum_type.values.items())
                }
            )
            return GraphQLEnumType(**kwargs)
        elif is_input_object_type(type_):
            kwargs = type_.to_kwargs()
            input_object_type = cast(GraphQLInputObjectType, type_)
            kwargs.update(fields=lambda: sort_input_fields(input_object_type.fields))
            return GraphQLInputObjectType(**kwargs)

        # Not reachable. All possible types have been considered.
        raise TypeError(f"Unexpected type: '{inspect(type_)}'.")  # pragma: no cover

    type_map: Dict[str, GraphQLNamedType] = {
        type_.name: sort_named_type(type_)
        for type_ in sorted(schema.type_map.values(), key=sort_by_name_key)
    }

    return GraphQLSchema(
        types=list(type_map.values()),
        directives=[
            sort_directive(directive)
            for directive in sorted(schema.directives, key=sort_by_name_key)
        ],
        query=replace_maybe_type(schema.query_type),
        mutation=replace_maybe_type(schema.mutation_type),
        subscription=replace_maybe_type(schema.subscription_type),
        ast_node=schema.ast_node,
    )
274359
def find_types_added_to_unions(
    old_schema: GraphQLSchema, new_schema: GraphQLSchema
) -> List[DangerousChange]:
    
    old_type_map = old_schema.type_map
    new_type_map = new_schema.type_map

    types_added_to_union = []
    for new_type_name, new_type in new_type_map.items():
        old_type = old_type_map.get(new_type_name)
        if not (is_union_type(old_type) and is_union_type(new_type)):
            continue
        old_type = cast(GraphQLUnionType, old_type)
        new_type = cast(GraphQLUnionType, new_type)
        type_names_in_old_union = {type_.name for type_ in old_type.types}
        for type_ in new_type.types:
            type_name = type_.name
            if type_name not in type_names_in_old_union:
                types_added_to_union.append(
                    DangerousChange(
                        DangerousChangeType.TYPE_ADDED_TO_UNION,
                        f"{type_name} was added to union type {new_type_name}.",
                    )
                )
    return types_added_to_union
566875
def graphql_queries_to_json(*queries):
    
    rtn = {}
    for i, query in enumerate(queries):
        rtn["q{}".format(i)] = query.value
    return json.dumps(rtn)
552856
def schema
      OpenGraph::TYPES.each_pair do |schema, types| 
        return schema if types.include?(self.type)
      end
      nil
    end
469093
function listToGraphQLEnumType(list, name) {
  const values = reduce(list, (values, val) => {
    values[val] = { value: val };
    return values;
  }, {});
  return new GraphQLEnumType({ name, values });
}
221384
function parse_where_type_condition(query, type) {
	if(type === undefined) {
		return;
	}

	if(is.array(type)) {
		return parse_where_type_condition_array(query, type);
	}

	if(is.string(type)) {
		// NOTE: We need to use `get_type_id()` until we fix the possibility that some
		// older rows do not have correct `type` field -- these are rows that were created
		// before their current validation schema and do not pass it.
		//query.where( new Predicate("types_id = get_type_id($)", type) );

		// schema v18 should have fixed type's for all documents
		query.where( new Predicate("type = $", type) );

		return;
	}

	if(type instanceof NoPg.Type) {
		query.where( new Predicate("types_id = $", type.$id) );
		return;
	}

	throw new TypeError("Unknown type: " + util.inspect(type));
}