Generates a GraphQL query that returns one entity by ID

@param string $typeName
@param Type[] $typeFields
@return string
774458
public static function generate(string $typeName, array $typeFields): string
    {
        $arguments = [];

        //Loop through fields to find the 'ID' field.
        foreach ($typeFields as $fieldName => $field) {
            if (false === ($field instanceof IDType)) {
                continue;
            }

            $arguments[] = sprintf('%s: %s! @eq', $fieldName, $field->name);
            break;
        }

        if (count($arguments) < 1) {
            return '';
        }

        $queryName = lcfirst($typeName);
        $query = sprintf('    %s(%s)', $queryName, implode(', ', $arguments));
        $query .= sprintf(': %1$s @find(model: "%1$s")', $typeName);

        if (config('lighthouse-utils.authorization')) {
            $permission = sprintf('find%1$s', $typeName);
            $query .= sprintf(' @can(if: "%1$s", model: "User")', $permission);
        }

        GraphQLSchema::register($queryName, $typeName, 'query', $permission ?? null);

        return $query;
    }
1351742
public static final int getSQLType(final String typeName) {
        String trimmedTypeName = typeName.trim().toLowerCase(Locale.US);
        final Integer n = pgGenericTypeNameToSQLTypeMap.get(trimmedTypeName);
        if (n == null) {

            // look up the alias
            trimmedTypeName = pgGenericTypeNameAliasMap.get(trimmedTypeName);
            if (trimmedTypeName != null) {
                return pgGenericTypeNameToSQLTypeMap.get(trimmedTypeName);
            }

            return Types.OTHER;
        } else {
            return n;
        }
    }
246125
protected function createType($typeName)
    {
        if (isset($this->typeCache[$typeName])) {
            return clone $this->typeCache[$typeName];
        }


        if (!$this->hasExtension($typeName)) {
            $class = $this->typeToClassName($typeName);
            $this->typeCache[$typeName] = new $class();
            return clone $this->typeCache[$typeName];
        }

        $this->typeCache[$typeName] = $this->callExtension($typeName, [$typeName, $this]);

        return clone $this->typeCache[$typeName]->setName($typeName);
    }
52975
public static function parse($typeName)
    {
        $normalize = array("int" => self::INTEGER_NAME, 
            "bool" => self::BOOLEAN_NAME, 
            "double" => self::FLOAT_NAME,
            "real" => self::FLOAT_NAME,
            "long" => self::INTEGER_NAME);

        if (isset($normalize[$typeName]))
            $typeName = $normalize[$typeName];

        if (self::$cachedTypes === null)
        {
            self::$cachedTypes = array(
                self::INTEGER_NAME => new PrimitiveType(self::INTEGER_NAME),
                self::FLOAT_NAME => new PrimitiveType(self::FLOAT_NAME),
                self::STRING_NAME => new PrimitiveType(self::STRING_NAME),
                self::BOOLEAN_NAME => new PrimitiveType(self::BOOLEAN_NAME),
                self::MIXED_NAME => new PrimitiveType(self::MIXED_NAME),
                self::RESOURCE_NAME => new PrimitiveType(self::RESOURCE_NAME),
                self::OBJECT_NAME => new PrimitiveType(self::OBJECT_NAME),
                self::NULL_NAME => new PrimitiveType(self::NULL_NAME),
                self::CALLABLE_NAME => new PrimitiveType(self::CALLABLE_NAME));
        }

        if (isset(self::$cachedTypes[$typeName]))
            return self::$cachedTypes[$typeName];

        return null;
    }
1314738
public function getStorage($typeName)
    {
        if (!isset($this->storageMap[$typeName])) {
            $this->storageMap[$typeName] = new NullStorage();
        } elseif (!$this->storageMap[$typeName] instanceof FieldStorage) {
            if (!is_callable($this->storageMap[$typeName])) {
                throw new \RuntimeException("FieldStorage '$typeName' is neither callable or instance");
            }

            $factory = $this->storageMap[$typeName];
            $this->storageMap[$typeName] = call_user_func($factory);
        }

        return $this->storageMap[$typeName];
    }
1063036
public function createEntity($className, array $fields = [])
    {
        $metadata = $this->getEntityMetadata($className);

        if (is_null($metadata)) {
            return null;
        }

        $reflection = $metadata->getReflectionClass();

        try {
            $entity = $reflection->newInstance();
        } catch (\Exception $e) {
            $entity = $reflection->newInstanceWithoutConstructor();
        }

        foreach ($fields as $fieldName => $fieldValue) {
            if (self::IDENTITY === $fieldName) {
                $property = $reflection->getProperty($this->getEntityIdName($className));
            } else {
                $property = $reflection->getProperty($fieldName);
            }

            try {
                $property->setValue($entity, $fieldValue);
            } catch (\Exception $e) {
                $property->setAccessible(true);
                $property->setValue($entity, $fieldValue);
                $property->setAccessible(false);
            }
        }

        return $entity;
    }
901769
private function findByBindingType($typeName)
    {
        $matches = array();

        $expr = Expr::isInstanceOf('Puli\Discovery\Binding\ResourceBinding');

        foreach ($this->discovery->findBindings($typeName, $expr) as $binding) {
            /** @var ResourceBinding $binding */
            foreach ($binding->getResources() as $resource) {
                $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource));
            }
        }

        ksort($matches);

        return $matches;
    }
235189
public static function values($typeName)
    {
        $db = static::getDb();

        return $db->createCommand(
            'SELECT unnest(enum_range(NULL::' . $db->quoteColumnName($typeName) . '))'
        )->queryColumn();
    }
577472
public static function namedType(string $typeName): NamedTypeNode
    {
        return self::validateType(
            self::parseType($typeName),
            NamedTypeNode::class
        );
    }
741275
public function bind($typeName)
	{
		if($this->proxyTypes !== NULL)
		{
			$this->proxyTypes = NULL;
		}
		
		$key = strtolower($typeName);
		
		switch($key)
		{
			case 'koolkode\config\configuration':
			case 'koolkode\context\containerinterface':
			case 'koolkode\context\exposedcontainerinterface':
			case 'koolkode\context\scope\scopedcontainerinterface':
				throw new \InvalidArgumentException(sprintf('Binding %s is forbidden', $typeName));
		}
		
		if(isset($this->bindings[$key]))
		{
			return $this->bindings[$key];
		}
		
		return $this->bindings[$key] = new Binding($typeName);
	}
705654
public static function get($name): Type
    {
        //internal type
        if ($internalType = self::getInternalType($name)) {
            return $internalType;
        }

        //convert FQCN into type,
        //allowing the use of FQCN for GraphQL scalar types
        if (class_exists($name) || interface_exists($name)) {
            if (\in_array($name, self::$typesMap, true)) {
                $name = array_flip(self::$typesMap)[$name];
            } elseif (self::$endpoint->hasTypeForClass($name)) {
                $name = self::$endpoint->getTypeForClass($name);
            }
        }

        if (!self::has($name)) {
            self::create($name);
        }

        if (self::has($name)) {
            return self::$types[$name];
        }

        throw new InvalidTypeException($name);
    }
621703
public static QueryBuilder byInstanceId(Object localId, String typeName){
        Validate.argumentsAreNotNull(localId, typeName);
        return new QueryBuilder(new IdAndTypeNameFilterDefinition(localId, typeName));
    }
746399
public static function exists($typeName)
    {
        $db = static::getDb();

        return $db->createCommand(
            'SELECT EXISTS ('
            . 'SELECT 1 '
                . 'FROM ' . $db->quoteTableName('pg_type')
                . ' WHERE typname = ' . $db->quoteValue($typeName)
            . ')'
        )->queryScalar();
    }
657083
public function RecurseFieldMaps($typename, $fms)
	{

		// if we see the same table again, we have an infinite loop
		if (isset($this->_keymapcache[$typename]))
		{
			// return;  // TODO: why doesn't this work..?
			throw new Exception("A circular EAGER join was detected while parsing `$typename`.  This is possibly due to an EAGER join with `".$this->_prevkeymap."`  Please edit your Map so that at least one side of the join is LAZY.");
		}

		// first we just add the basic columns of this object
		foreach ($fms as $fm)
		{
			$this->AddFieldMap($fm);
		}
		
		// get the keymaps for the requested object
		$kms = $this->_phreezer->GetKeyMaps($typename);
		$this->_keymapcache[$typename] = $kms;  // save this to prevent infinite loop
		$this->_prevkeymap = $typename;
		
		// each keymap in this object that is eagerly loaded, we want to join into the query.
		// each of these tables, then might have eagerly loaded keymaps as well, so we'll use
		// recursion to eagerly load as much of the graph as is desired
		foreach ($kms as $km)
		{
			if ($km->LoadType == KM_LOAD_EAGER || $km->LoadType == KM_LOAD_INNER)
			{
				// check that we didn't eagerly join this already.
				// TODO: use aliases to support multiple eager joins to the same table
				if (isset($this->Joins[$km->ForeignObject . "_is_joined"]))
				{
					//print_r($typename);
					throw new Exception($typename ."Map has multiple EAGER joins to `" . $km->ForeignObject . "` which is not yet supported by Phreeze.");
				}
				
				$ffms = $this->_phreezer->GetFieldMaps($km->ForeignObject);
				
				$this->RecurseFieldMaps($km->ForeignObject, $ffms);
				
				// lastly we need to add the join information for this foreign field map
				$jointype = $km->LoadType == KM_LOAD_INNER ? "inner" : "left";
				
				foreach ($ffms as $ffm)
				{
					if (!isset($this->Joins[$ffm->TableName]))
					{
						$this->Joins[$ffm->TableName] = " ".$jointype." join `".$ffm->TableName."` on `" . $fms[$km->KeyProperty]->TableName . "`.`" .  $fms[$km->KeyProperty]->ColumnName . "` = `" . $ffms[$km->ForeignKeyProperty]->TableName . "`.`" . $ffms[$km->ForeignKeyProperty]->ColumnName . "`";
					}

				}
				
				// keep track of what we have eagerly joined already
				$this->Joins[$km->ForeignObject . "_is_joined"] = 1;
			}
		}
	}
1291794
public static function generate(array $typeFields): array
    {
        foreach ($typeFields as $fieldName => $field) {
            $className = get_class($field);
            if ($className === IDType::class) {
                return [
                    sprintf('%s: %s!', $fieldName, $field->name)
                ];
            };
        }

        return [];
    }
1214823
public function get(string $typeName) : TypeSchema
    {
        if (!array_key_exists($typeName, $this->types)) {
            throw NotFoundException::model($typeName);
        }

        return $this->types[$typeName];
    }
1150597
protected static function query($fields)
    {
        $result = Query::from(static::$table);

        $result = $result->where();

        foreach ($fields as $key => $value) {
            $result = $result->andWhere($key, '=', $value);
        }

        return $result->get();
    }